我可以执行“独特”操作吗?使用 WCF 数据服务 (OData) 查询?
我确实需要能够对 WCF 数据服务查询执行“DISTINCT”。
据我所知,这样的功能不存在。我知道我可以在客户端的 Linq 查询中使用 Distinct 扩展方法,但它仍然会合并完整的结果集(在这种特殊情况下这不是我想要的)。
有什么想法吗?
I really need to be able to perform a 'DISTINCT' on a WCF Data Service query.
From what I can tell, such a function doesn't exist. I know that I can use the Distinct extension method in the Linq query on the client, but it still hydrates the full result set (which isn't what I want in this particular case).
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不是内置的。它目前也根本不是 OData 协议的一部分(除了计数之外没有聚合,我们肯定需要考虑它)。推荐的方法是检索所有数据并在客户端上执行设置操作(哎呀!)。
也就是说,您必须以某种方式在客户端和服务器上扩展 WCF 数据服务才能提供此功能(我对它不够熟悉,无法为您指出正确的钩子)。
您始终可以提供一个
WebMethod
(顺便说一句,这只是 WCF)来完成这项工作,但我想这不是您打算使用数据服务的方式。Not built in. It's also not currently part of the OData protocol at all (no aggregation is other than count, which we would definitely need to even consider it). The recommended approach is to retrieve all data and do set operations on the client (yuck!).
That said, you'd have to somehow extend WCF Data Services on both the client and server to provide this functionality (I'm not familiar enough with it to point you to the right hooks).
You could always go with providing a
WebMethod
(this is just WCF by the way) to do this work, but I would imagine that's not how you intend to use Data Services.我建议使用 WCF 数据服务、服务操作 - http://msdn。 microsoft.com/en-us/library/cc668788.aspx,作为更好的解决方案(通过网络方法)。服务操作是封装 OData 查询语法未启用的查询功能的好方法。
I'd recommend using a WCF Data Service, Service Operation - http://msdn.microsoft.com/en-us/library/cc668788.aspx, as a better solution (over a webmethod). Service Operations are a great way to encapsulate query functionality not enabled by the OData query syntax.