4.2.1.5 Retrieve a Collection of Entities with an Inline Count by Using the AtomPub Format

The following example illustrates the exchange of messages required for a client to retrieve a collection of Order entities related to a specific Customer entity and include the count of all orders associated with the Customer entity in the response from the data service. This example is supported in the OData 2.0 and OData 3.0 protocols.

Request:

 GET /service.svc/Customers('ALFKI')/Orders?$inlinecount=allpages HTTP/1.1
 Host: host
 Accept: application/atom+xml
 DataServiceVersion: 2.0
 MaxDataServiceVersion: 3.0

Response:

 HTTP/1.1 200 OK
 Date: Fri, 12 Dec 2008 17:17:11 GMT
 Content-Type: application/atom+xml;type=feed
 Content-Length: nnn
 DataServiceVersion: 3.0
  
 <feed  xml:base="http://host/service.svc/"
        xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
        xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
        xmlns="http://www.w3.org/2005/Atom">
         <title type="text">Orders</title>
         <id>http://host/service.svc/Customers('ALFKI')/Orders</id>
         <updated>2008-03-30T21:52:46Z</updated>
         <link rel="self" title="Orders" href="Customers('ALFKI')/SampleModel.Customer/Orders" />
         <m:count>2<m:count>
         <entry>
           <category term="SampleModel.Order"
             scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
           <id>http://host/service.svc/Orders(1)</id>
           <title type="text" />
           <updated>2008-03-30T21:52:45Z</updated>
           <author>
             <name />
           </author>
           <link rel="edit" title="Orders" href="Orders(1)/SampleModel.Order" />
           <link
       rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Customer"
                 type="application/atom+xml;type=entry" title="Customer"
                 href="Orders(1)/SampleModel.Order/Customer" />
           <link
       rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Customer"
                 type="application/xml " title="Customer"
                 href="Orders(1)/SampleModel.Order/$links/Customer" />
           <link
       rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/OrderLines"
                 type="application/atom+xml;type=feed" title="OrderLines"
                 href="Orders(1)/SampleModel.Order/OrderLines" />
           <link
       rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/OrderLines"
                 type="application/ xml " title="OrderLines"
                 href="Orders(1)/SampleModel.Order/$links/OrderLines" />
           <content type="application/xml">
             <d:OrderID m:type="Edm.Int32">1</d:OrderID>
             <d:ShippedDate m:type="Edm.DateTime">1997-08-25T00:00:00</d:ShippedDate>
           </content>
         </entry>
         <entry>
           <category term="SampleModel.Order"
             scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
           <id>http://host/service.svc/Orders(2)</id>
           <title type="text" />
           <updated>2008-03-30T21:52:45Z</updated>
           <author>
             <name />
           </author>
           <link rel="edit" title="Orders" href="Orders(2)/SampleModel.Order " />
           <link
        rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Customer"
                 type="application/atom+xml;type=entry" title="Customer"
                 href="Orders(2)/SampleModel.Order/Customer" />
           <link
        rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/Customer"
                 type="application/ xml " title="Customer"
                 href="Orders(2)/SampleModel.Order/$links/Customer" />
           <link
       rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/OrderLines"
                 type="application/atom+xml;type=feed" title="OrderLines"
                 href="Orders(2)/SampleModel.Order/OrderLines" />
           <link
       rel="http://schemas.microsoft.com/ado/2007/08/dataservices/relatedlinks/OrderLines"
                 type="application/ xml " title="OrderLines"
                 href="Orders(2)/SampleModel.Order/$links/OrderLines" />
           <content type="application/xml">
             <d:OrderID m:type="Edm.Int32">2</d:OrderID>
             <d:ShippedDate m:type="Edm.DateTime">1997-10-03T00:00:00</d:ShippedDate>
           </content>
         </entry>
 </feed>