Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OData V4 Contains and any

We have an OData V4 endpoint with the following structure. We are using Entity Framework 6.1, OData V4 and Web Api 2.2

http://api.com/odata/Companies

and if we want to get the address we simply expand like this

http://api.com/odata/Companies?$expand=Addresses

If I filter by city it works nice

http://api.com/odata/Companies?$filter=Addresses/any(a:a/City eq 'New York')

But we cannot apply Contains to the filter. What is the correct syntax to achieve Contains with the City property?

like image 317
Raffaeu Avatar asked Dec 26 '22 05:12

Raffaeu


1 Answers

One part of the correct syntax is to have the letters of built-in query option "contains()" all in lower case, in case the reason that you failed to apply it to the filter is because the casing isn't right.

You can see the following query to the TripPin sample service as an example of the whole syntax:

http://services.odata.org/v4/TripPinServiceRW/People?$filter=Trips/any(a:contains(a/Name,'US'))&$expand=Trips
like image 113
Yi Ding - MSFT Avatar answered Jan 19 '23 16:01

Yi Ding - MSFT