Search code examples
jsonkendo-uiodata

Odata: The query parameter '$count' is not supported


Server: Odata controllers generated with standard VS 2015 generator.

// GET: odata/MyEntities
[EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)]
public IQueryable<Models.Odata. MyEntity> GetMyEntities()
{
  return db.MyEntities;
}

Client: KendoUI

var ds = new kendo.data.HierarchicalDataSource({
  type: "odata-v4",
  transport: {
    read: {
      url: "odata/EndPoints",
      dataType: "json"
    }
  },
  schema: {
            model: {
                id: "Id",
            }
        }
  });

Request:

http://localhost:44444/odata/MyEntities?$format=json - returns whats expected, but

http://localhost:44444/odata/MyEntities?$format=json&$count=true - produces error:

{
  "odata.error":{
    "code":"","message":{
      "lang":"en-US","value":"The query parameter '$count' is not supported."
    }
  }
}

I used standard settings in AppStart. What is it?


Solution

  • OData version 3 has a query option named $inlinecount, not $count. It appears you are confusing the query option with both the /$count path segment, and the $count query option from version 4.

    Request the total count of entities in a collection, along with the entities themselves:

    GET http://localhost:44444/odata/MyEntities?$format=json&$inlinecount=allpages
    

    Request only the count of an entity collection:

    GET http://localhost:44444/odata/MyEntities/$count?$format=json
    

    See OData Version 3.0 Core Protocol, sections 10.2.3.6 and 10.2.5.