4
votes

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)?

1
Can't it just be a version problem ? this support has been added with v5.5. I tested the sample with v5.5.1 and it is actually working. Which version are you using (6.1.0 doesn't exist yet) ? - Fabian
Many thanks @Fabian. I have three libraries with the oData icon that report version 6.1.0 and then the library that you linked to that, I can now see, reports 5.4.0, I guess this is the main library! Your comment has just made a good start to what is going to be a very long day. Thanks again. :-) - lukkea
Is it working ? Can I add an answer to close the topic ? - Fabian
please do, and I'll mark it as answered. - lukkea

1 Answers

2
votes

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)