Skip to main content

filter-one-to-many

OData V4 introduces lambda operators e.g., any/all so that the root property of the one-to-many navigation properties can be filtered. Below is an example that demonstrates how to use the lambda operator any.

/*
Get all people that have at least one friend that matches all the following conditions:
- Has first name 'John'
- Has last name 'Miller'
*/
.filter(
any(
People.FRIENDS.filter(
People.FIRST_NAME.equals('John'),
People.LAST_NAME.equals('Miller')
)
)
)

The generated $filter parameter of the URL will be:

$filter=(/any(a0:((a0/Friends/FirstName eq 'John' and a0/Friends/LastName eq 'Miller'))))