odata查询嵌套导航属性上的$ filter

时间:2018-03-09 12:50:32

标签: entity-framework odata wcf-data-services

我有一个包含订单导航属性的实体客户和包含产品导航属性(一个多个)的订单。

现在我如何过滤所有客户订购的特定产品。我已经尝试过如下所述的每个排列,但它会抛出odata异常:

试用1)客户?$ filter =订单/产品/任何(d:d / ProductCode eq'code1')

试用2)客户?$ expand =订单($ expand =产品))& $ filter =订单/产品/任何(d:d / ProductCode eq'code1')

试用3)客户?$ expand =订单($ expand =产品))& $ filter =订单/任意(d:d / Products / ProductCode eq'code1')

请为odata查询建议正确的格式。

1 个答案:

答案 0 :(得分:2)

我认为您需要两个不同的any条款,因为我认为您要求" 任何订单的客户反过来 any 具有产品代码' code1'"

的产品

所以我认为它应该是这样的:

Customers?$filter= Orders/any(o: o/Products/any(p: p/ProductCode eq 'code1'))

以下是使用示例TripPin OData服务的示例:http://services.odata.org/V4/TripPinServiceRW/People?$filter=Friends/any(f:%20f/Trips/any(t:%20t/Name%20eq%20'Trip%20in%20US'))&$expand=Friends($expand=Trips)

相关问题