本文介绍了哪里的WebAPI 2.2的OData v4的[EnableQuery]申请?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是哪里正确/不正确应用EnableQueryAttribute为2015年1月的?

Where is it correct/incorrect to apply the EnableQueryAttribute as of Jan 2015?

该文件链接如下:

http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/create-an-odata-v4-endpoint

说:

在[EnableQuery]属性使客户修改查询,通过查询选项,如$过滤,排序$和$页。有关详细信息,请参阅支持的OData查询选项。

以下链接的文档:

http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options

说:

该EnableQuerySupport方法使查询选项全球范围内为返回一个IQueryable类型的任何控制器动作。

但这个文档的OData 4的WebAPI 2.2已经把它在返回IHttpActionResult操作:

But this document for OData 4 on WebApi 2.2 has put it on actions returning IHttpActionResult:

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]申请?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 20:09