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

I have a web api 2.2 that is configured for OData v4. I want to return the user by identifier and include only the identifier of the user group of which the user is a member. When i do it

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

I get this error

The request specified in the URI is invalid. Found a path with several navigation properties in the select clause. Rewrite the query so that each selection or extension level contains only TypeSegments or Properties.

Found a path with several navigation properties in the select clause. Modify your query so that each selection or extension level contains either TypeSegments or Properties.

The request will be executed if I delete ", userGruops / id"

+5
source share
1 answer

You should write your request as follows:

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

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

+3
source

Source: https://habr.com/ru/post/1207710/


All Articles