10

I'm using WebAPI 2.2 with OData V4.

It is possible for me to use $filter=RelatedObj/PropertyName eq 'Some Value' to filter a list of entities based on a related object property value.

However, when I try to use the same syntax with $select:

$select=Id,Name,RelatedObj/PropertyName

results in exception:

"message": "The query specified in the URI is not valid. 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.",
"innererror": {
"message": "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.",
"type": "Microsoft.OData.Core.ODataException",

Can this be solved?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
BuddhiP
  • 6,231
  • 5
  • 36
  • 56

2 Answers2

17

You can do it using $expand and nested $select query option

$select=Id,Name&$expand=RelatedObj($select=PropertyName)

See the ODATA documentation

avitenberg
  • 1,781
  • 19
  • 16
  • This doesn't work for (some?) properties. I get the error: "Invalid $select properties." I don't think the above syntax is supported for Microsoft Graph API (neither beta nor v1): https://learn.microsoft.com/en-us/graph/known-issues#query-parameter-limitations – VinnyQ77 Apr 07 '21 at 18:53
0

If you want to perform a $select on an item under a navigation property, you need to first $expand the navigation property.

EntitySet?$select=Id,Name,RelatedObj/PropertyName&$expand=RelatedObj
mitch
  • 985
  • 10
  • 12