次の方法で共有


Accessing Data Service Resources (ADO.NET Data Services)

ADO.NET Data Services exposes data as resources that are addressable by URIs. These resources are represented according to the entity-relationship conventions of the Entity Data Model (EDM). In this model, entities represent operational units of data that are data types in an application domain, such as customers, orders, items, and products. Entity data is accessed and changed by using the semantics of representational state transfer (REST), specifically the standard HTTP verbs of GET, PUT, POST, and DELETE.

In ADO.NET Data Services, you address entity resources as an entity set that contains instances of entity types. For example, the following URI from the quickstart returns all instances of a Customer entity type:

https://localhost:12345/Northwind.svc/Customers

Note

When developing a data service with Visual Studio, the default configuration of your data service host name is in the format of localhost:<port number>. After the service is deployed, the host name is the URI of the server that is hosting the data service.

Entities have special properties called entity keys. An entity key is used to uniquely identify a single entity in an entity set. This enables you to address a specific instance of an entity type in the entity set. For example, the following URI returns a specific instance of the Customer entity type that has a key value of ALFKI:

https://localhost:12345/Northwind.svc/Customers('ALFKI')

Scalar properties of an entity instance can be individually addressed. For example, the following URI returns the ContactName property value for a specific Customer:

https://localhost:12345/Northwind.svc/Customers('ALFKI')/ContactName

Relationships between entities are defined in the data model by associations. These associations enable you to address sets of related entities as if they were exposed as navigation properties of an entity instance. For example, the following URI returns all the Orders that are related to a specific Customer:

https://localhost:12345/Northwind.svc/Customers('ALFKI')/Orders

ADO.NET Data Services also enables you to address resources based on the results of query expressions. This makes it possible to select sets of resources on an evaluated expression. For example, the following URI filters the resources to return only the Orders for the specified Customer that have shipped since September 22, 1997:

https://localhost:12345/Northwind.svc/Customers('ALFKI')/Orders?$filter=ShippedDate gt datetime'1997-09-22T00:00:00'

For more information, see Addressing Resources (ADO.NET Data Services).

Query expressions enable you to perform traditional query operations against resources, such as filtering, sorting, and paging. Query expressions are composed of one or more query options, such as $filter or $orderby, used with logical comparison operators, arithmetic operators, and predefined query functions. For example, the following URI returns all orders the postal codes of which do not end in 100:

https://localhost:12345/Northwind.svc/Orders?$filter=not endswith(ShipPostalCode,'100')

For more information, see Query Expressions (ADO.NET Data Services).

In addition to addressing entity sets and entity instances, ADO.NET Data Services also enables you to address the associations that represent relationships between entities. This functionality is required to be able to create or change a relationship between two entity instances, such as the shipper that is related to a given order in the Northwind sample database. ADO.NET Data Services supports a $link operator to specifically address the associations between entities. For example, the following URI is specified in an HTTP PUT request message to change the shipper for the specified order to a new shipper.

https://localhost:12345/Northwind.svc/Orders(10643)/$links/Shippers

The URI of a data service resource enables you to address entity data exposed by the service. When you enter a URI into the address field of a Web browser, a data feed representation of the requested resource is returned. For more information, see the ADO.NET Data Services Quickstart. Although a Web browser may be useful for testing that a data service resource returns the expected data, production data services that can also create, update, and delete data are generally accessed by application code or scripting languages in a Web page. For more information, see Using a Data Service in a Client Application (ADO.NET Data Services).

See Also

Other Resources

Quickstart (ADO.NET Data Services)

Addressing Resources (ADO.NET Data Services)