【问题标题】:MaxExpansionDepth with latest webapi and breezeMaxExpansionDepth 与最新的 webapi 和微风
【发布时间】:2013-11-09 05:25:42
【问题描述】:

我最近将我所有的 nuget 包更新为最新的 EF6、breeze 1.4.5、system.web.http.odata 5.0.0.0 以及所有其他可用的好位。

现在,对于一个包含像 x.y.z 这样的扩展的查询,我收到如下错误:

A first chance exception of type 'Microsoft.Data.OData.ODataException' occurred in System.Web.Http.OData.dll

Additional information: The request includes a $expand path which is too deep. The maximum depth allowed is 2. To increase the limit, set the 'MaxExpansionDepth' property on QueryableAttribute or ODataValidationSettings.

我查看了建议的修复。如果我在被查询的微风“端点”上添加一个 Queryable 属性,它似乎会导致各种其他问题。我的猜测是它会干扰微风的预期行为并以不同的方式格式化结果。

然后我通过 GlobalConfiguration.Configuration... 研究了使用 HttpConfiguration EnableQuerySupport 扩展方法...,但这似乎没有效果(请参阅Supporting OData Query Options

有人知道如何更改默认的 webapi 行为吗?

谢谢。

【问题讨论】:

    标签: asp.net-web-api odata breeze


    【解决方案1】:

    你需要像这样为你的微风控制器 IQueryable 方法添加一个 BreezeQueryable 属性...

        [BreezeQueryable(MaxExpansionDepth = 3)]
        public IQueryable<Customer> Customers()
        {
            ...
        }
    

    【讨论】:

    • 完美!谢谢。想知道为什么它现在才开始抱怨吗?一定是在最新的 webapi 版本中发生了变化。
    • 您也可以在控制器级别应用它:stackoverflow.com/questions/21635376/…
    • 对我们来说,我们需要使用 BreezeNHQueryable
    • 'BreezeQueryableAttribute' 已过时,使用 EnableBreezeQueryAttribute 类 - [EnableBreezeQuery(MaxExpansionDepth = 3)]
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-02
    相关资源
    最近更新 更多