Use OData $ select for cherry pick fields from related object

I am using WebAPI 2.2 with OData V4.

Can be used $filter=RelatedObj/PropertyName eq 'Some Value'to filter the list of objects based on the property value of the associated object.

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

$select=Id,Name,RelatedObj/PropertyName

results in an 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?

+4
source share
2 answers

You can do this with the option $expandand nested $selectqueries.

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

See ODATA documentation

+6
source

If you want to execute $selectin an element under the navigation property, you first need the $expandnavigation property.

EntitySet?$select=Id,Name,RelatedObj/PropertyName&$expand=RelatedObj
-1
source

All Articles