Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the ADO.NET data service framework

Shulou Source: shulou.com Published: 2022-06-02 08:17:58 10月26日 Update

This article mainly explains "how to use the ADO.NET data service framework". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use the ADO.NET data service framework.

Service operations can be used in situations where business logic is required, such as when implementing validation logic or security. Service operations allow developers to define a method on a server identified by URI (similar to other ADO.NET data service resources). These service operations are methods added to classes derived from the DataService that represent the data service.

Creation service operation of ADO.NET data service framework

To implement a service operation, define a public instance method as part of a data service class derived from the DataService class that represents the data service.

◆ this method can only accept the [in] parameter.

◆ if parameters are defined, the type of each parameter must be a primitive type.

◆ this method must return void, IEnumerable, IQueryable, T, or primitive classes such as integers or strings.

◆ T must be a class that represents an entity type in the data model that the data service will expose.

◆ to support query options such as sorting, paging, and filtering, the service action method should return IQueryable.

◆ must annotate this method with the [WebGet] or [WebInvoke] attributes.

◆ [WebGet] enables you to call this method by using a GET request.

◆ [WebInvoke] enables you to call this method by using a PUT, POST, or DELETE request.

You can use SingleResultAttribute to annotate service operations, specifying that the return value of this method is an entity rather than a set of entities. This distinction determines the serialization of the generated response. For example, when using AtomPub serialization, a single instance of a resource type is represented as an entry element, and a single instance set is represented as a feed element. If a method does not follow the convention defined above, the method is not exposed as a service operation in the data service. Address the service operation.

According to the ADO.NET data service protocol specification, service operations can be addressed by placing the name of the method in * path segments of the URI. You can add additional path segments or query options to this URI, depending on the return type of the service operation. The following example implements service operations for a data service that exposes a model based on an entity framework.

Public class Northwind: DataService {public static void InitializeService (IDataServiceConfiguration config) {/ / Entity sets access configuration. Config.SetEntitySetAccessRule ("*", EntitySetRights.AllRead) / / Service operations access configuration. Config.SetServiceOperationAccessRule ("OrdersByCity", ServiceOperationRights.All);} [WebGet] public IQueryable OrdersByCity (string city) {if (string.IsNullOrEmpty (city)) {throw new ArgumentNullException ("city", "You must provide a city name argument");} return this.CurrentDataSource.Orders.Where ("it.ShipCity = @ city", new ObjectParameter ("city", city)) }} Thank you for reading, the above is the content of "how to use the ADO.NET data service framework". After the study of this article, I believe you have a deeper understanding of how to use the ADO.NET data service framework, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Services data methods frameworks this method types entities parameters instances learning elements content individual sequence case annotations models resources paths logic Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Tech Info MariaDB Xiaomi Shulou Information