Friday, March 11, 2016

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

Leave a Comment

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"

1 Answers

Answers 1

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.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment