Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when using $select and $expand with Odata v4.0 on Web API 2.2

I have a web api 2.2 that is configured for OData v4. I want to return a user by ID and include only the user group Id's that the user is a member of. When I do this

http://localhost/User?$filter=id eq 312&$select=*,userGroups/id&$expand=userGroups

I get this error

The query specified in the URI is not valid. Found a path with multiple navigation properties in a select clause. Please reword your query such that each level of select or expand only contains either TypeSegments or Properties.

Found a path with multiple navigation properties in a select clause. Please reword your query such that each level of select or expand only contains either TypeSegments or Properties.

The query will execute if I remove ",userGruops/id"

like image 555
Brett Feagans Avatar asked Nov 26 '14 05:11

Brett Feagans


1 Answers

You should write your query like this:

http://localhost/User?$filter=id eq 312&$select=*&$expand=userGroups($select=id)

By the way, you can also remove the $select=* segment as all non-navigation properties are by default included in the response.

like image 59
Yi Ding - MSFT Avatar answered Dec 31 '22 14:12

Yi Ding - MSFT