Search code examples
c#asp.netasp.net-web-apiodata

oData v4 (6.1.0) nested $filter in $expand


I have an asp.net 4.5 Web Api oData v4 service that is working really well but I have encountered a problem today with nested $filters in $expand.

It says here

that OData V4 supports nested filters in $expand. The request below return People and all their trips with Name "Trip in US".

GET serviceRoot/People?$expand=Trips($filter=Name eq 'Trip in US')

and it shows a nice example of data that does just that.

There is also a coded example in the Web API for oData v4 Docs here

I have an HTTP call like this:

serviceRoot/Languages?$expand=translations

which returns a list of Languages with their expanded translations and I can filter that top-level list down with this:

serviceRoot/Languages?$expand=translations&$filter=isoLanguageShortName eq 'en'

However, I can't filter the expanded translations with this:

serviceRoot/Languages?$expand=translations($filter=languageName eq 'English')

That call seems to be the same as the one in the quote above and the effect should be same on my data as theirs.

Does anyone know where am I going wrong? Do I need to set something in my ASP.NET code for this to work (like we need to add MaxExpansionDepth to EnableQueryAttribute for querying deeper than two levels)?


Solution

  • It is a versioning problem. The support for has been added with version 5.5. I tested the sample with v5.5.1 and it is actually working.

    As @lukkea confirmed he was using 5.4.0.

    (Version 6.1.0 indicated in the title corresponds to odata core libraries which is a dependency of odata web api library Microsoft.AspNet.OData)