Paulo Pinto
Paulo Pinto

Reputation: 427

MVC4 WebApi OData $count not working with IQueryable

I have a simple Get action in a Controller in MVC4:

// GET /branches
// returns a list of available branches
[Queryable]
public IQueryable<string> Get() {
    return BranchesRepository.GetBranchNames().AsQueryable();
}

This works perfectly when I call it just with a GET and even with some OData options like $top, $skip and $filter. But it doesn't work when I call it with $count.

e.g:

/branches/$count

returns

[]

whereas I'd expect to see a number.

The response header gives me a version for asp.net that I'm using

X-AspNet-Version: 4.0.30319

Is the $count parameter broken in this version? Or is there something I can do to get it to work?

Upvotes: 3

Views: 1862

Answers (1)

Filip W
Filip W

Reputation: 27187

Are still using beta/RC version of Web API? IF so, only $top, $skip, $orderby and $filter were supported. Moreover, QueryableAttribute was removed in the RTM release.

OData is now supported in Web API only via a preview package http://www.nuget.org/packages/Microsoft.AspNet.WebApi.OData.

But that does not support $count at the moment anyway.

Upvotes: 2

Related Questions