The ADO.NET Data Services Framework implements an addressing scheme that uses URIs to locate data. The entity-relationship patterns of the Entity Data Model are used to organize data as entities and associations with entities logically grouped in entity sets. These patterns are reflected in the URI addressing scheme.
To describe the system by example, a customer-tracking service is used in the following examples. All Customer entities are addressed by the following URI.
http://myserver/data.svc/Customers
The /Customers segment of the URI points to the set of Customer entities specified in the metadata. ADO.NET Data Services Framework metadata is equivalent to the conceptual schema in the EDM. The entity set, Customers, logically contains all instances of the Customer entity type.
In this syntax, the following URI retrieves a single Customer entity whose key property, as defined in metadata, has a value of 'ALFKI'.
http://myserver/data.svc/Customers('ALFKI')
Entities and Associations
Metadata describes the structure of entity types and associations between entities. The ADO.NET Data Services Framework leverages this information to provide a mechanism for association traversal. For example, if each of the Customer entities in the data service has a set of Orders associated with it, the following URI represents the set of sales orders associated with the Customer whose primary key has a value of 'ALFKI'.
http://myserver/data.svc/Customers('ALFKI')/Orders
The properties of a Customer entity can be addressed individually. For example, the following URI represents the ContactName of the Customer entity with key 'ALFKI':
http://myserver/data.svc/Customers('ALFKI')/ContactName
In addition to key-based queries, simple predicates can be included in the addressing scheme. This makes it possible to select sets of data based on the properties of entities, such as the set of currently active Orders for the Customer with the key 'ALFKI'. This data is retrieved by the following URI:
http://myserver/data.svc/Customers('ALFKI')/Orders?$filter=Active eq true
The $filter operator used in the preceding example can also be used in conjunction with string, math, or date functions. The following URI represents the set of active orders made in the year 2007 for the Customer 'ALFKI':
http://myserver/data.svc/Customers('ALFKI')/Orders?$filter=
Active eq true and (year(OrderDate) eq 2007)
If the Orders have other related entities, the URI can continue to drill down into the association graph, traverse associations, and filter each of the resulting sets.
Presentation Control Information
ADO.NET Data Services URIs can also include information in the query string that sorts data. Common requirements for Internet applications include paging the data and sorting by properties. The following URI lists Orders entities sorted by date:
http://myserver/data.svc/Customers('ALFKI')/Orders?$filter=
Active eq true&$orderby=OrderDate
Paging results is done by combining the parameters $skip and $top. In a list of customers, numbers 31-41 are obtained by the following URI:
http://myserver/data.svc/Customers?$skip=30&$top=10
GET, PUT, POST, and DELETE
The syntax in the previous examples is used in an HTTP GET request to retrieve entities and collections of entities. To update entities or relationships, ADO.NET Data Services uses HTTP PUT syntax. Similarly, HTTP POST syntax is used to create new entities, and HTTP DELETE syntax is used to eliminate entities from storage. For more information, see Client Applications of ADO.NET Data Services.
See Also