ADO. NET data service 1

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.