Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 723
Jonathan Avatar asked Jun 04 '12 17:06

Jonathan


2 Answers

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

like image 185
MartinF Avatar answered Nov 12 '22 06:11

MartinF


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

like image 10
Vinney Kelly Avatar answered Nov 12 '22 06:11

Vinney Kelly