Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is is possible to filter on an OData navigation property?

A USERS collection contains a USERGROUPS navigation property.

Users are accessed through /api/Users?$expand=USERGROUPS.

USERGROUPS navigation property contains ID, and I would like to filter by UserGroups.Id by something like:

/api/Users?$expand=USERGROUPS&$filter=startswith(USERGROUPS/ID,'a')

Ultimately I'd like to be able to filter on a specific group ID value.

Thanks.

like image 530
ElHaix Avatar asked Dec 01 '22 20:12

ElHaix


1 Answers

Actually OData V3 supports something like that with the any/all operator. So for example if you want to search for all users which belong to user group with id 'a' the query would look something like:

/api/Users?$filter=USERGROUPS/any(usergroup: usergroup/ID eq 'a')

Note though, that the feature is only supported in OData V3, so you need to enable that on the server.

like image 155
Vitek Karas MSFT Avatar answered Dec 10 '22 01:12

Vitek Karas MSFT