odata - 结合 $expand 和 $select

odata - combining $expand and $select

在 odata v4.0 中是否有将 $expand 和 $select 组合在一起的选项?

I have a scenario wherein I'm trying to get specific columns in productItemChoices and item. The below query will give you all the columns in productItemChoices. I only need one column in the productItemChoices

odata/Products(08f80b45-68a9-4a9f-a516-556e69e6bd58)?$expand=productItemChoices($expand=item($select=name))

在select中,您可以使用entity/attribute到select扩展实体的特定属性:

$select=productItemChoices/columnyouwant

我不确定您查询中实体的关系。深入扩展时,我使用了以下语法(不带括号)- 在下文中,我假设产品与 productItemChoices 相关,并且 productItemChoices 具有项目

$expand=productItemChoices, productItemChoices/item

然后,select

$select=productItemChoices/productItemChoicesGuid, productItemChoices/item/name

显然,如果关系不同,您需要对其进行一些更改

在这个问题上折腾了很久,我终于得到了答案。我们可以使用 ; 作为分隔符将 select 嵌套在 expand 中,例如

odata/Products(8)?$expand=choices($select=col1,col2;$expand=item($select=name))

这记录在 OData v4 $expand documentation 中。该文档还列出了其他有用的示例,例如

Categories?$expand=Products($filter=DiscontinuedDate eq null)
Categories?$expand=Products/$count($search=blue)