Linq OData“哪里”嵌套列表上的子句
假设我有以下查询 OData Linq 查询(针对 http://odata.netflix.com/v2/Catalog 运行):
Genres.Where(x=>x.Name=="Adventures")
.Select(y=> new
{
Genre = y.Name,
Movie = y.Titles.Select(l=> new
{
l.Name,
l.AverageRating
})
})
如何更改此查询以提供 AverageRating 为 3 的行?
(注意:这个问题的重点是找出如何对我的主级别查询项的扩展子列表的属性执行 where 子句。我的真正查询甚至不是针对 Netflix OData feed。)
Say I have the following query OData Linq Query (run against http://odata.netflix.com/v2/Catalog):
Genres.Where(x=>x.Name=="Adventures")
.Select(y=> new
{
Genre = y.Name,
Movie = y.Titles.Select(l=> new
{
l.Name,
l.AverageRating
})
})
How could I change this query to give me the rows where AverageRating was 3?
(NOTE: The point of this question is to find out how to do a where clause on properties of an expanded sub list of my main level query item. My real query is not even against the Netflix OData feed.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的回答是目前不可能。
$filter 始终(且仅)适用于顶级实体集。目前无法过滤扩展实体集。
$filter 可以到达扩展实体集内部,但结果将始终过滤顶级实体集。在 V2 中,它适用于单例导航属性($filter 中的表达式可以遍历这些属性),在 V3 中,您可以使用 any/all 来合并集合导航属性。
这不起作用的原因是 OData 协议没有定义嵌套过滤器的 URI 语法。事实上,除了扩展本身和投影之外,它几乎没有在扩展实体集上定义任何运算符。
The short answer is that it's not possible currently.
The $filter always (and only) applies to the top-level entity set. There's currently no way to filter expanded entity sets.
The $filter can reach inside the expanded entity sets but the result will always filter the top-level set. In V2 it works for singleton navigation properties (the expression in $filter can traverse those), in V3 you can use the any/all to also incorporate collection navigation properties.
The reason this can't work is that the OData protocol doesn't define the URI syntax for nested filters. In fact it doesn't define almost any operator on the expanded entity sets except for the expansion itself and projections.