2.2.6.3.2.1 InlineCount Representation (for Collections of Entities)

Applies to the OData 2.0 and OData 3.0 protocols

This section defines the semantics of the "countNVP" grammar rule in section 2.2.6.3.2, which is supported only in OData 2.0 and OData 3.0.

A request URI MAY contain an $inlinecount system query option to indicate that the count of the number of entities represented by the query after filters have been applied ought to be included in the collection of entities returned from a data service. If such a query string object is present, the response MUST include the "countNVP" name/value pair with the value of the name/value pair equal to the count of the total number of entities addressed by the request URI.

The "countNVP" name/value pair MUST NOT be inside the Inline Representation of a related collection (section 2.2.6.3.9.1).

For example, the count of all Customer Entities using the Customer EntityType instance described in Appendix A: Sample Entity Data Model and CSDL Document (section 6) is represented in Verbose JSON as shown in the following sample response payload. This example assumes the request URI includes the InlineCount system query option and the Top system query option with a value of 1.

 {
   d:{
      "__count": "91",
      "results":[
      { 
        "__metadata": { "uri": "Customers(\'ALFKI\')",
                        "type": "SampleModel.Customer",
                        "etag": "W/\"X\'000000000000FA01\'\"",
                        "properties" : {
                              "Orders" : {
                                     "associationuri" : "Customers(\'ALFKI\')/$links/Orders"
                              }
                        } 
                      },
        "CustomerID": "ALFKI",
        "CompanyName": "Alfreds Futterkiste",
        "Address": { "Street": "57 Contoso St", "City": "Seattle" },
        "Version": "AAAAAAAA+gE=",
        "Orders": {
           "results": [
             {
                "__metadata": { "uri": "Orders(1)",
                                "type": "SampleModel.Order",
                                "properties" : {
                                  "Customer" : {
                                    "associationuri" : "Orders(1)/$links/Customer",
                                  },
                                  "OrderLines" : {
                                    "associationuri" : "Orders(1)/$links/OrderLines",
                                  }
                                } 
                              },
                "OrderID": 1,
                "ShippedDate": "\/Date(872467200000)\/",
                "Customer":   { "__deferred": { "uri": "Orders(1)/Customer"} },
                "OrderLines": { "__deferred": { "uri": "Orders(1)/OrderLines"} }
             },
             {
                "__metadata": { "uri": "Orders(2)",
                                "type": "SampleModel.Order",
                                "properties" : {
                                  "Customer" : {
                                    "associationuri" : "Orders(2)/$links/Customer",
             .                    },
                                  "OrderLines" : {
                                    "associationuri" : "Orders(2)/$links/OrderLines",
                                  }
                                } 
                              },
                "OrderID": 2,
                "ShippedDate": "\/Date(875836800000)\/",
                "Customer":   { "__deferred": { "uri": "Orders(2)/Customer"} },
                "OrderLines": { "__deferred": { "uri": "Orders(2)/OrderLines"} }
            }
          ]
        }
      ]
   }
 }

Listing: OData 3.0 Verbose JSON-Formatted InlineCount representation