5

I have OData source, that implements $skip and $top parameters. There are x number of entities that are returned. Say, I have only 250 entities. And then I try to do the paging like this:

https://example.com/EntitySet?$top=30&$skip=220

If my skip goes beyond the number of total entities, I eventually get timeout from service.

Is there a parameter or data, that would inform me that there are no more items? Is there something that can/should be implemented on OData side, that gets returned instead of timeout?

Tschareck
  • 4,071
  • 9
  • 47
  • 74

2 Answers2

7

For OData 2.0 and OData 3.0 protocols: You should use: $inlinecount=allpages

http://services.odata.org/OData/OData.svc/Products$inlinecount=allpages&$top=5&$format=json

Identifies the first 5 Product Entries and includes a count of the total number of Product Entries.

For OData 4.0, you can read the nextLink annotation embeded in the response. (See example here)

4.5.5 Annotation odata.nextLink The odata.nextLink annotation indicates that a response is only a subset of the requested collection of entities or collection of entity references. It contains a URL that allows retrieving the next subset of the requested collection.

Yoram
  • 572
  • 6
  • 21
5

If you add &$count=true to your uri the service will include a total count in the response. The json response will include a "@odata.count" property. This property indicates the total number of entities.

That way you can check if you've received all entities.

GWigWam
  • 2,013
  • 4
  • 28
  • 34
  • How do you retrieve the value of @odata.count on the client side if you are using Microsoft ODATA Client Proxy in VS 2017. – Iftikhar Ali Oct 08 '18 at 16:57
  • If I'm able to tell ODATA MS Client to include the Total Count by using IncludeTotalCount() method on DataServiceQuery, there must be a way to retrieve that value? Or I'm wrong? – Iftikhar Ali Oct 08 '18 at 17:45
  • @IftikharAli You are right, I think it is explained [here](https://technet.microsoft.com/nl-nl/library/ee474390(v=vs.103).aspx), see the example for how to access the result. (I have not tried this myself) – GWigWam Oct 08 '18 at 19:09