哪里的WebAPI 2.2的OData v4的[EnableQuery]申请? [英] Where does WebAPI 2.2 OData v4 [EnableQuery] apply?
问题描述
这是哪里正确/不正确应用EnableQueryAttribute为2015年1月的?
Where is it correct/incorrect to apply the EnableQueryAttribute as of Jan 2015?
该文件链接如下:
<一个href=\"http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-endpoint\" rel=\"nofollow\">http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-endpoint
说:
在[EnableQuery]属性使客户修改查询,通过查询选项,如$过滤,排序$和$页。有关详细信息,请参阅支持的OData查询选项。
The [EnableQuery] attribute enables clients to modify the query, by using query options such as $filter, $sort, and $page. For more information, see Supporting OData Query Options.
以下链接的文档:
<一个href=\"http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options\" rel=\"nofollow\">http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options
说:
该EnableQuerySupport方法使查询选项全球范围内为返回一个IQueryable类型的任何控制器动作。
The EnableQuerySupport method enables query options globally for any controller action that returns an IQueryable type.
但这个文档的OData 4的WebAPI 2.2已经把它在返回IHttpActionResult操作:
But this document for OData 4 on WebApi 2.2 has put it on actions returning IHttpActionResult:
<一个href=\"http://blogs.msdn.com/b/webdev/archive/2014/03/13/getting-started-with-asp-net-web-api-2-2-for-odata-v4-0.aspx\" rel=\"nofollow\">http://blogs.msdn.com/b/webdev/archive/2014/03/13/getting-started-with-asp-net-web-api-2-2-for-odata-v4-0.aspx
[ODataRoutePrefix("Teams")]
public class TeamsEntitySetController : ODataController
{
private readonly LeageContext _leage = new LeageContext();
[EnableQuery]
[ODataRoute]
public IHttpActionResult GetFeed()
{
return Ok(_leage.Teams);
}
[ODataRoute("({id})")]
[EnableQuery]
public IHttpActionResult GetEntity(int id)
{
return Ok(SingleResult.Create<Team>(_leage.Teams.Where(t => t.Id == id)));
}
}
我要疯了试图找到OData的V4 /的WebAPI了最新的,准确和一致的文档2.2。
I'm going crazy trying to find up-to-date, accurate and consistent documentation on OData v4 / WebApi 2.2.
今天是正确的?
推荐答案
使用全局配置(一个HttpConfiguration对象的实例),并调用
Use global configuration (instance of an HttpConfiguration object) and call
config.Filters.Add(new EnableQueryAttribute()
{
PageSize = 2
// .. other settings
});
这个作品
这篇关于哪里的WebAPI 2.2的OData v4的[EnableQuery]申请?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!