Jonathan
Jonathan

Reputation: 1755

ASP.Net MVC4 RC Web-Api Odata filter not working with IQueryable

In ASP.net MVC4 RC's Web-api, I had a Get action defined like before:

public IQueryable<Person> Get()
    {
        var lst = ctx.GetListFromDB();
        return lst.AsQueryable();
    }

When it was I was running it before if I called a url like: /api/people?$inlinecount=allpages&$format=json&$top=50&$filter=(State+eq+'AL'+and+Zip+eq+'35242')

It would do the filtering on the objects, has something changed since the beta that would break this?

Upvotes: 14

Views: 7502

Answers (3)

Vinney Kelly
Vinney Kelly

Reputation: 5095

So, apparently this feature has been removed from the final release schedule. I guess that means we'll need to modify existing WebAPI action methods to include the necessary filtering, sorting, and paging parameters for now. Very sad indeed.

http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/af11adf6b3c5

Upvotes: 10

MartinF
MartinF

Reputation: 5979

You have to put the [Queryable] attribute on the method to allow filtering. The release notes describing the change are here.

Update: In RTM they seem to have separated this feature into its own assembly so you have to include a reference to the ASP.NET Web API OData assembly from Microsoft. You can find the latest version on Nuget https://nuget.org/packages/Microsoft.AspNet.WebApi.OData

Update: In the latest version the Queryable attribute have been renamed to EnableQuery. For more information about changes see http://blogs.msdn.com/b/webdev/archive/2014/03/13/getting-started-with-asp-net-web-api-2-2-for-odata-v4-0.aspx

Upvotes: 41

AlignedDev
AlignedDev

Reputation: 8232

From what I see (on 9/20/12) you need the https://nuget.org/packages/Microsoft.AspNet.WebApi.OData/0.1.0-alpha-120815 Nuget package to get this to work. Unfortunately, it's still in pre-release. The [Queryable] attribute is in this package.

I haven't found very good information on this.

Upvotes: 1

Related Questions