2
votes

I've inherited some code and does stuff with OData and I've spent some time on it to no avail so now I need some help please

I have a database that has a table called Client and another with ClientContacts

What I need to be able to do is using OData, get a list of clients what have a contact first name that contains ‘Chris’

This is what I tried to start with but obviously this won’t work as client contracts are a collection localhost:55992/api/ClientApi/GetAllClients?$expand=ClientContacts,Client&$filter=substringof('',ClientName) and substringof('Chris',ClientContacts/ContactFirstName)&$top=20&$skip=0&$inlinecount=allpages

It gives me the following exception "The parent value for a property access of a property 'ContactFirstName' is not a single value. Property access can only be applied to a single value."

I think I need to use the Any command but I can’t for the life of me figure out, any help will be much appreciated

1

1 Answers

5
votes

The syntax for using a filter with the any operator looks like this:

$filter=ClientContacts/any(contact: substringof('Chris',contact/ContactFirstName))