ADO.NET Data Services
What is ADO.NET Data Services? |
It is a framework that consists of a combination of patterns and libraries that enable the creation and consumption of data services for the web. The ADO.NET Data Services framework is Microsoft’s technology for creating and consuming data services. These data services use the Entity Data Model (EDM) to model data in terms of entities. These entities are exposed as URI-addressable resources that can be accessed using standard HTTP requests.
Why is ADO.NET Data Services
To facilitate the creation of flexible data services that are naturally integrated with the web.
Data in the form of URIs
As such, ADO.NET Data Services use URIs to point to pieces of data and simple, well-known formats to represent that data, such as JSON and ATOM (XML-based feed format).
Based on standard HTTP protocols
This results in the data service being surfaced as a REST-style resource collection that is addressable with URIs and that agents can interact with using standard HTTP verbs such as GET, POST, PUT or DELETE.
Exposes data that you have modeled
Your data exposed through ADO.NET Data Services must be based upon modeled data using Entity Data Model (EDM), an Entity-Relationship derivative. This organizes the data in the form of instances of "entity types", or "entities", and the associations between them.
1: https://myserver/data.svc/Customers
2: https://myserver/data.svc/Customers(‘ALFKI’)
3: https://myserver/data.svc/Customers(‘ALFKI’)/ContactName
4: https://myserver/data.svc/Customers(‘ALFKI’)/Orders
5: https://myserver/data.svc/Customers(‘ALFKI’)?$expand=Orders,AlternateContacts
6: https://myserver/data.svc/Customers(‘ALFKI’)/Orders?$filter=Active eq true
7: https://myserver/data.svc/Customers(‘ALFKI’)/Orders?$filter=Active eq true and (year(OrderDate) eq 2007)
8: https://myserver/data.svc/Customers(‘ALFKI’)/Orders?$filter=Active eq true&$orderby=OrderDate
9: https://myserver/data.svc/Customers?$skip=30&$top=10
The REST-based URIs above can be used to query for data exposed in ADO.NET Data Services
Line 1 | Displays the "/Customers" part of the URI points to the Customers entity-set, which is the container for Customer instances. |
Line 2 | Displays the results in a single Customer entity whose key, as defined in the EDM schema, has a value of "ALFKI". |
Line 3 | Displays the Contact Name of the Customer entity with key “ALFKI”: |
Line 4 | Display the customers in the data service has a set of Sales Orders associated with it, associated with the Customer whose key has a value of “ALFKI”. |
Line 5 | Displays alternate contact information is to be returned inline in the same response from the data service. |
Line 6 | Display set of active sales orders for the customer with key 'ALFKI' |
Line 7 | Display line 6 with an order year of 2007 |
Line 8 | Display line 6 sorted by order date. |
Line 9 | Display the results with paging built in. |
Multiple Web Protocols are supported
ADO.NET Data Services uses minimalistic formats to represent data, and supports more than one format to accommodate as many client agents as possible.
Currently ADO.NET Data Services can represent data in JSON (JavaScript Object Notation) and AtomPub (Atom Publishing Protocol) formats.
Examples |
REST-URI Query
1: https://myserver/data.svc/Customers(‘ALFKI’)
The Payload Returned
If an HTTP GET request is sent to the URI above, the data service would respond with a payload similar to that shown below. The application of simple and clear semantics from the data model to URIs and payloads in various formats result in uniform patterns for interacting with data services.
Re-usable Components
These uniform patterns present the opportunity to create reusable components that build on top of the patterns and the semantics behind them and provide powerful abstractions for developers.
This is AtomPub format:
1: <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
2: <entry xml:base="https://myserver/data.svc/" xmlns:d="https://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="https://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="https://www.w3.org/2005/Atom">
3: <id>https://myserver/data.svc/Customers('ALFKI')</id>
4: <updated>2008-08-31T21:36:21Z</updated>
5: <title />
6: <author>
7: <name />
8: </author>
9: <category term="NorthwindModel.Customers" scheme="https://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
10: <content type="application/xml">
11: <d:CustomerID>ALFKI</d:CustomerID>
12: <d:CompanyName>Alfreds Futterkiste</d:CompanyName>
13: <d:ContactName>Maria Anders</d:ContactName>
14: <d:ContactTitle>Sales Representative</d:ContactTitle>
15: <d:Address>Obere Str. 57</d:Address>
16: <d:City>Berlin</d:City>
17: <d:Region m:null="true" />
18: <d:PostalCode>12209</d:PostalCode>
19: <d:Country>Germany</d:Country>
20: <d:Phone>030-0074321</d:Phone>
21: <d:Fax>030-0076545</d:Fax>
22: </content>
23: <link rel="edit" href="Customers('ALFKI')" title="Customers" />
24: <link rel="https://schemas.microsoft.com/ado/2007/08/dataservices/related/Orders" title="Orders" href="Customers('ALFKI')/Orders" type="application/xml;type=feed" />
25: <link rel="https://schemas.microsoft.com/ado/2007/08/dataservices/related/CustomerDemographics" title="CustomerDemographics" href="Customers('ALFKI')/CustomerDemographics" type="application/xml;type=feed" />
26: </entry>
Line 3 | The original query |
Lines 11 to 21 | The results of the query |
Separation of presentation and data |
The Client can request different data format
The client agent can choose another format by simply changing the Accept header in the HTTP request. For example, by setting the Accept header to "application/json" the client agent would obtain the following result in JSON format instead of the AtomPub format shown above. This JSON format below.
1: “d”:{
2: __metadata: {
3: uri: "Customers(\'ALFKI\')",
4: type: "NorthwindModel.Customers"
5: },
6: CustomerID: "ALFKI",
7: CompanyName: "Alfreds Futterkiste",
8: ContactName: "Maria Anders",
9: ContactTitle: "Sales Representative",
10: Address: "Obere Str. 57",
11: City: "Berlin",
12: Region: null,
13: PostalCode: "12209",
14: Country: "Germany",
15: Phone: "030-0074321",
16: Fax: "030-0076545",
17: Orders: {
18: __deferred: {
19: uri: "Customers(\'ALFKI\')/Orders"
20: }
21: }
22:
23: CustomerDemographics: {
24: __deferred: {
25: uri: "Customers(\'ALFKI\')/CustomerDemographics"
26: }
27: }
28: }
JSON makes sense in an AJAX-based application
While semantically equivalent, this version will integrate naturally and easily with JavaScript environments such as AJAX-based applications.
JSON format supports web scenarios
With JSON you can list customer entities, show the list in pages, allow the user to filter based on simple criteria and to click on different columns to change the sort order. I would also be able to support in-place editing, creation and deletion of customer rows.
The ADO.NET Data Services framework includes a client library for the .NET Framework and Silverlight that can expose a data service in terms of .NET objects and supports association traversal, identity resolution and other simple, yet powerful data programming constructs.
ADO.NET Data Services includes a JavaScript library
In addition, the ADO.NET Data Services Framework includes a JavaScript library (available on www.codeplex.com) to simplify inserting, updating and deleting resources from AJAX applications.
ADO.NET Data Services is described with an EDM conceptual schema
ADO.NET Data Service is described using an Entity Data Model (EDM) conceptual schema. An EDM conceptual schema ( https://msdn2.microsoft.com/en-us/library/bb399281(VS.90).aspx) is an XML document written using the conceptual schema definition language (CSDL) which describes entities and the associations among those entities
Comments
- Anonymous
August 09, 2009
The comment has been removed