使用 OData 和 LINQ 获取链接集合的计数
我按照精彩文章 使用 LINQPad 查询堆栈溢出,我想做类似的事情:
Users.Where(x=>x.Badges.Count==0).Take(5)
获取没有徽章的用户 ("徽章?我们不需要臭徽章!”)。我收到一个 DataServiceQueryException:
I set up the OData feed for Stack Overflow as outlined in the wonderful article Using LINQPad to Query Stack Overflow and I want to do something like:
Users.Where(x=>x.Badges.Count==0).Take(5)
to get the users that have no Badges ("Badges? We don't need no stinkin' badges!"). I get a DataServiceQueryException:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
遗憾的是,OData 不支持聚合函数 - 它仅支持此处描述的有限查询函数集。
希望 Microsoft 将来能够增强 OData 客户端 - 令人沮丧的是(看似)拥有 LINQ 的所有功能,但却无法使用它。
Unfortunately, OData doesn't support aggregate functions - it supports only the limited set of querying functions described here.
Hopefully Microsoft will enhance the OData client in the future - it is frustrating to (seemingly) have all the power of LINQ and then not be able to use it.
看起来 Badges 没有 Count 属性。这就是异常发生的原因。
您可能需要处理每个用户以检查徽章导航属性是否解析为任何内容。
Looks like Badges doesn't have a Count property. This is why the exception occurred.
Probably you'd need to process each User to check whether the Badges navigation property resolves to anything.
当前不支持对导航属性中的实体计数进行过滤(如上面 Joe Albahari 已指出的)。在最新的 CTP 中,OData 支持允许您过滤“空”导航属性的任何和所有功能。
请参阅
以下是对任意/全部功能的讨论:
Filtering on count of entities in navigation properties is currently not supported (as already noted by Joe Albahari above). In the latest CTP OData supports any and all functions which would allow you to filter on "empty" navigation properties.
See
Here is a discussion of the any/all feature: