ing.alfano
ing.alfano

Reputation: 436

OData V4 more than one option in $expand

in OData V4 inside an $expand query you can nest as an option:

1)$expand

http://services.odata.org/V4/OData/OData.svc/Categories?$expand=Products($expand=ProductDetail)

2)$levels

Entities($expand=ChildItems($level=x)) where ChildItem is the same type of Entity

3)$select

http://services.odata.org/V4/OData/OData.svc/Categories?$expand=Products($select=Price)&$select=Name,Products

I would like to expand ProductDetail like this but of course it does not work

http://services.odata.org/V4/OData/OData.svc/Categories?$expand=Products($expand=ProductDetail&$select=Price,ProductDetail)&$select=Name,Products

This call gets

Query parameter '$select' is specified, but it should be specified exactly once

so you would think that you can $select only on the main entity but case #3 works perfectly.

I know that I could rewrite my query to achieve my objectives but I would like to know if this is possible.

Thanks, Alessandro

Upvotes: 8

Views: 14742

Answers (1)

ing.alfano
ing.alfano

Reputation: 436

The key is the separator. You have to separate each option with ";". I found the answer here

Case 3 becomes

http://services.odata.org/V4/OData/OData.svc/Categories?$expand=Products($select=Price,ProductDetail;$expand=ProductDetail)&$select=Name,Products

Upvotes: 18

Related Questions