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 of the following conditions:
- Has first name 'John'
- Has last name 'Miller'
*/
.filter(
peopleApi.schema.FRIENDS.filter(
any(
peopleApi.schema.FIRST_NAME.equals('John'),
peopleApi.schema.LAST_NAME.equals('Miller')
)
)
)

The generated $filter parameter of the URL will be:

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