Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can odata total records be found without fetching them?

Tags:

odata

Am creating paging and fetching 10 JSON records per page:

  var coursemodel = query.Skip(skip).Take(take).ToList();

I need to display on the web page the total number of records available in database. For example, you are viewing 20 to 30 of x (where x is total number of records). Can x be found without transferring the records over the network?

like image 479
Steve Avatar asked Mar 28 '14 18:03

Steve


People also ask

What are some of the things that an OData service contains?

A URL used by an OData service has at most three significant parts: the service root URL, resource path and query options.

How do I filter OData query?

You can use filter expressions in OData requests to filter and return only those results that match the expressions specified. You do this by adding the $filter system query option to the end of the OData request.

What is $Top and $skip?

$top and $skip are used to limit the amount of data. This is done by calculating an offset and the number of records to return. The offset is set using the $skip system query option and the number of items returned via the $top system query option.

What is $expand in OData?

OData expand functionality can be used to query related data. For example, to get the Course data for each Enrollment entity, include ?$ expand=course at the end of the request path: This tutorial uses Postman to test the web API.


2 Answers

Sorted it. Did this

http://yourserver7:40479/odata/Courses?$top=1&skip=1&$inlinecount=allpages

Got this

 {
  "odata.metadata":"http://yourserver7:40479/odata/$metadata#Courses","odata.count":"503","value":[
    {
      "CourseID":20,"Name":"Name 20","Description":"Description 20","Guid":"Guid 20"
    }
  ]
}

I then got the value from odata.count! My url gets all records found, add $filter where applicable...

like image 186
Steve Avatar answered Sep 24 '22 08:09

Steve


You can use the $count operator to return the total number of records, something along these lines:

http://services.odata.org/OData/OData.svc/Categories(1)/Products/$count

Not sure what the syntax would be with Linq, but pretty sure it is possible.

PS - Always a good reference: http://www.odata.org/documentation/odata-version-2-0/uri-conventions/

like image 39
Nuno Linhares Avatar answered Sep 24 '22 08:09

Nuno Linhares