4.2.1.6 Retrieve a Collection of Entities with an Inline Count by Using the Verbose JSON 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 a count of all orders associated with the Customer entity from a data service. This example is supported only 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/json;odata=verbose
 DataServiceVersion: 2.0
 MaxDataServiceVersion: 3.0

Response:

 HTTP/1.1 200 OK
 Date: Fri, 12 Dec 2008 17:17:11 GMT
 Content-Type: application/json;odata=verbose
 Content-Length: nnn
 DataServiceVersion: 3.0
  
 {"d": [
          {
             "__count": "2"
          },
          {
             "__metadata": { "uri": "Orders(1)",
                             "type": "SampleModel.Order",
                             "properties" : {
                               "Customer" : {
                                 "associationuri" : "Orders(1)/SampleModel.Order/$links/Customer"
                               },
                               "OrderLines" : {
                                 "associationuri" : "Orders(1)/SampleModel.Order/$links/OrderLines"
                               }}    
                           },
             "OrderID": 1,
             "ShippedDate": "\/Date(872467200000)\/",
             "Customer":   { "__deferred": { "uri": "Orders(1)/SampleModel.Order/Customer" } }
             "OrderLines": { "__deferred": { "uri": "Orders(1)/SampleModel.Order/OrderLines" } }
          },
          {
             "__metadata": { "uri": "Orders(2)",
                             "type": "SampleModel.Order",
                             "properties" : {
                               "Customer" : {
                                 "associationuri" : "Orders(2)/SampleModel.Order/$links/Customer"
                               },
                               "OrderLines" : {
                                 "associationuri" : "Orders(2)/SampleModel.Order/$links/OrderLines"
                               }}    
                           },
             "OrderID": 2,
             "ShippedDate": "\/Date(875836800000)\/",
             "Customer":   { "__deferred": { "uri": "Orders(2)/SampleModel.Order/Customer" } }
             "OrderLines": { "__deferred": { "uri": "Orders(2)/SampleModel.Order/OrderLines" } }
  
          }
 ]}
Show: