MaxExpansionDepth with latest webapi and breeze
Asked Answered
B

1

8

I have recently updated all of my nuget packages to the latest for EF6, breeze 1.4.5, system.web.http.odata 5.0.0.0, and all the other good bits available.

Now, with one query that contains an expansion like x.y.z I get an error as follows:

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.

I looked into the suggested fixes. If I add a Queryable attribute on the breeze 'endpoint' being queried, it appears to cause all sorts of other problems. My guess is it interferes with breeze's expected behaviour and formats the results differently.

I then looked into the using the HttpConfiguration EnableQuerySupport extension method, through GlobalConfiguration.Configuration..., but that appears to have no effect (see Supporting OData Query Options)

Does anybody have any idea how I can change the default webapi behaviour?

Thanks.

Bellied answered 29/10, 2013 at 20:43 Comment(0)
A
20

you need to add a BreezeQueryable attribute to your breeze controller IQueryable method like this ...

    [BreezeQueryable(MaxExpansionDepth = 3)]
    public IQueryable<Customer> Customers()
    {
        ...
    }
Alleras answered 30/10, 2013 at 17:1 Comment(4)
Perfect! Thanks. Wonder why it only started complaining now? Must have been a change in the latest webapi release.Bellied
You can also apply it on a controller level:#21635876Structuralism
For us, we needed to use the BreezeNHQueryableNara
'BreezeQueryableAttribute' is obsolete use the EnableBreezeQueryAttribute class - [EnableBreezeQuery(MaxExpansionDepth = 3)]Philosophical

© 2022 - 2024 — McMap. All rights reserved.