← Prev in month ← Prev in thread

Conflicting info for $count?

From
Mark Biamonte <>
Date
2015-02-02T21:45:02+00:00
ID
Thread
Conflicting info for $count?
In looking into the changes from OData v2 to OData v4 for $count, I am seeing what I believe is conflicting information.

 

In the OData v4 URL Conventions document, I find the following

 

To address the raw value of the number of items in a collection, clients append /$count to
 the resource path of the URL identifying the entity set or collection.  The count is calculated after applying any $filter or $search system
 query options to the collection. The returned count MUST NOT be affected by $top,$skip, $orderby,
 or $expand.

Example 26: the number of related entities

http://host/service/Categories(1)/Products/$count

Example 27: the number of entities in an entity set

http://host/service/Products/$count

Example 28: entity count in a $filter _expression_.
 Note that the spaces around gt are
 for readability of the example only; in real URLs they must be percent-encoded as %20.

http://host/service/Categories?$filter=Products/$count gt
 0

Example 29: entity count in an $orderby _expression_

http://host/service/Categories?$orderby=Products/$count

This says that $count returns the number of entities in the entity set, but not the actual entities.

 

In the OData v4 Protocol document I find

The $count system
 query option with a value of true specifies
 that the total count of items within a collection matching the request be returned along with the result.

Example 51: return, along with the results, the total number of products in the collection

http://host/service/Products?$count=true

The count of related entities can be requested by specifying the $count query
 option within the $expand clause.

Example 52:

http://host/service/Categories?$expand=Products($count=true)

A $count query
 option with a value of false (or
 not specified) hints that the service SHOULD NOT return a count.

The service returns an HTTP Status code of 400
 Bad Request if a value other than true or false is
 specified.

The $count system
 query option ignores any $top, $skip,
 or $expand query
 options, and returns the total count of results across all pages including only those results matching any specified $filter and $search.
 Clients should be aware that the count returned inline may not exactly equal the actual number of items returned, due to latency between calculating the count and enumerating the last value or due to inexact calculations on the service.

How the count is encoded in the response body is dependent upon the selected format.

 

This says the count is returned along with the entities in an entity set.

 

Which is the correct behavior for $count?

 

Thanks

Mark
← Prev in month ← Prev in thread