In ASP.net MVC4 RC's Web-api, I had a Get action defined like before:
在ASP.net MVC4 RC的Web-api中,我像以前一样定义了Get动作:
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')
如果我之前运行它,如果我调用了一个url:/ 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?
它会对对象进行过滤,自测试版以来会有什么变化会破坏这个吗?
3 个解决方案
#1
40
You have to put the [Queryable] attribute on the method to allow filtering. The release notes describing the change are here.
您必须在方法上放置[Queryable]属性以允许过滤。描述变化的发行说明就在这里。
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
更新:在RTM中,他们似乎将此功能分离到自己的程序集中,因此您必须包含对Microsoft的ASP.NET Web API OData程序集的引用。您可以在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
更新:在最新版本中,Queryable属性已重命名为EnableQuery。有关更改的更多信息,请参阅http://blogs.msdn.com/b/webdev/archive/2014/03/13/getting-started-with-asp-net-web-api-2-2-for-odata- v4-0.aspx
#2
10
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.
因此,显然此功能已从最终发布计划中删除。我想这意味着我们现在需要修改现有的WebAPI操作方法,以包含必要的过滤,排序和分页参数。确实很伤心。
http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/af11adf6b3c5
...Please don't down-vote me for being the bearer of bad news ;)
...请不要因为担心坏消息而拒绝投票;)
#3
1
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.
从我所看到的(2012年9月9日),您需要https://nuget.org/packages/Microsoft.AspNet.WebApi.OData/0.1.0-alpha-120815 Nuget包才能使其正常工作。不幸的是,它仍处于预发布状态。 [Queryable]属性在此包中。
I haven't found very good information on this.
我没有找到关于此的非常好的信息。
#1
40
You have to put the [Queryable] attribute on the method to allow filtering. The release notes describing the change are here.
您必须在方法上放置[Queryable]属性以允许过滤。描述变化的发行说明就在这里。
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
更新:在RTM中,他们似乎将此功能分离到自己的程序集中,因此您必须包含对Microsoft的ASP.NET Web API OData程序集的引用。您可以在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
更新:在最新版本中,Queryable属性已重命名为EnableQuery。有关更改的更多信息,请参阅http://blogs.msdn.com/b/webdev/archive/2014/03/13/getting-started-with-asp-net-web-api-2-2-for-odata- v4-0.aspx
#2
10
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.
因此,显然此功能已从最终发布计划中删除。我想这意味着我们现在需要修改现有的WebAPI操作方法,以包含必要的过滤,排序和分页参数。确实很伤心。
http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/af11adf6b3c5
...Please don't down-vote me for being the bearer of bad news ;)
...请不要因为担心坏消息而拒绝投票;)
#3
1
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.
从我所看到的(2012年9月9日),您需要https://nuget.org/packages/Microsoft.AspNet.WebApi.OData/0.1.0-alpha-120815 Nuget包才能使其正常工作。不幸的是,它仍处于预发布状态。 [Queryable]属性在此包中。
I haven't found very good information on this.
我没有找到关于此的非常好的信息。