I recently saw ADO. NET data service in my learning process. It seems to be very useful and I will use it today;
At present, his operating mechanism is not very clear. First, let's take an example to feel his benefits;
In the later learning process, you may learn more deeply, and enjoy a better understanding of its internal mechanisms;
First look at the creation process:
1. Create an ASP. NETProgram
2. Add a gridview control to the default page;
3. Add an ADO. NET Entity, as shown in.
Click OK
Click Next and select the table you are generating. The object is created;
4. Create an ADO. NET data services
Click OK, as shown in the following figure.Code:
NamespaceMydataservice {Public classWebdataservice1:Dataservice</* Todo: name of the data source class placed here */> {// Call this method only once to initialize the policy involving the service scope.Public static voidInitializeservice (IdataserviceconfigurationConfig ){// Todo: set rules to indicate which entity sets and service operations are visible and updatable. // Example: // config. setentitysetaccessrule ("myentityset", entitysetrights. allread); // config. setserviceoperationaccessrule ("myserviceoperation", serviceoperationrights. All );}}}
Modify the above Code to the following code:
Public classNorthwinddataservice:Dataservice<Northwndentities> {// Call this method only once to initialize the policy involving the service scope.Public static voidInitializeservice (IdataserviceconfigurationConfig ){// Todo: set rules to indicate which entity sets and service operations are visible and updatable. // Example:Config. setentitysetaccessrule ("Orders",Entitysetrights. Allread );// Config. setserviceoperationaccessrule ("myserviceoperation", serviceoperationrights. All );}}
Running Service:
The following figure is displayed:
Enter orders in the URL to display the number of records;
The data is displayed on the page. The data source is bound to the gridview. The Code is as follows:
Public partial class _ default : system. web. UI. page { protected void page_load ( Object sender, eventargs E) { northwinddataservice SS = New northwinddataservice (); dataservicecontext context = New dataservicecontext ( New
Uri("Http: // localhost: 7261/northwinddataservice. svc /"));This. Gridview1.datasource = context. Execute <Orders> (NewUri("Orders",Urikind. Relative ));This. Gridview1.databind ();}}
The running result is as follows:
This article is an entry-level sample code for ADO. NET data services,ArticleThe principle and process are not detailed.
I am also studying, and will provide it to you later,
Hope to help beginners;