Search code examples
odata

Can odata total records be found without fetching them?


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?


Solution

  • 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...