Reputation: 43
I have a Entity Customer containing Orders Navigation Property and Order containing Products Navigation Property(One-Many).
Now how i can filter all customers have ordered a Specific Product. I have tried every permutation as mentioned below but it is throwing odata exceptions:
trial 1) Customers?$filter=Orders/Products/any(d:d/ProductCode eq 'code1')
trial 2) Customers?$expand=Orders($expand=Products))&$filter=Orders/Products/any(d:d/ProductCode eq 'code1')
trial 3) Customers?$expand=Orders($expand=Products))&$filter=Orders/any(d:d/Products/ProductCode eq 'code1')
Please suggest correct format for odata query.
Upvotes: 1
Views: 3050
Reputation: 3681
I think that you need two different any
clauses here as I think that you are asking for "customers with any order that in turn has any product that has the product code 'code1'"
So I think that it should look like this:
Customers?$filter= Orders/any(o: o/Products/any(p: p/ProductCode eq 'code1'))
Here is an example using the example TripPin OData service: http://services.odata.org/V4/TripPinServiceRW/People?$filter=Friends/any(f:%20f/Trips/any(t:%20t/Name%20eq%20'Trip%20in%20US'))&$expand=Friends($expand=Trips)
Upvotes: 3