Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use OData $select to cherry pick fields from related object

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?

like image 798
BuddhiP Avatar asked Jun 16 '15 13:06

BuddhiP


1 Answers

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

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

See the ODATA documentation

like image 169
avitenberg Avatar answered Nov 08 '22 04:11

avitenberg