oData WCF Data Services Filter Child Collection

橙三吉。 提交于 2019-12-04 14:49:27

There are two things causing problems here. First, it sounds like you want to filter the Orders collection, not the Customers collection (i.e., you always want all Customers to be returned, but you only want certain Orders to be expanded). When you have a URI that looks like EntitySet?$filter=<some predicate>, the filter always applies to the EntitySet, which in your case is Customers (which is not what you want).

Secondly, the reason ~Customers?$expand=Orders&$filter=Orders/Amount gt 100 doesn't even filter the Customers correctly is because Orders is a collection of entities, not a single entity. Orders/Amount doesn't make sense if you think of Orders as a list, only Order/Amount does. If you wanted to have a filter that only returns Customers who have at least one Order where Order/Amount is greater than 100, you could use the any keyword:

~Customers?$expand=Orders&$filter=Orders/any(o: o/Amount ge 100)

But again, that filters the Customers, not the Orders.

Given that you want to actually be filtering the Orders, would the following work for you?

~Orders?$expand=Customer&$filter=Amount gt 100
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!