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

2

7

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"

Dunkin answered 26/11, 2014 at 5:56 Comment(0)
S
5

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.

Sharitasharity answered 26/11, 2014 at 9:37 Comment(3)
This works perfectly. I don't think Microsoft follows the OData specifications perfectly though. ThanksDunkin
@BrettFeagans I'm from OData team of Microsoft and I'm well connected to our college working on the URL parser in ODataLib. Would you shed light on what exactly isn't followed perfectly enough? We'd love to hear your feedback and improve our stack accordingly.Sharitasharity
@Yi Ding - FSFT / @Microsoft OData team This: https://graph.microsoft.com/v1.0/users?$select=*&$expand=manager($select=id) gives the error: "Invalid $select properties" While this: https://graph.microsoft.com/v1.0/users?$expand=manager&$select=id,displayName,manager/id gives the error: "Parsing OData Select and Expand failed: Found a path with multiple navigation properties or a bad complex property path in a select clause. Please reword your query such that each level of select or expand only contains either TypeSegments or Properties."Bluecollar
P
0

The Beta version of the API handles

https://graph.microsoft.com/beta/users?$select=id,surname&$expand=manager($select=id)
Pointtopoint answered 12/7, 2021 at 0:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.