在 Windows Phone 7 上过滤异步 OData 查询
我正在开发一个适用于 Windows Phone 7 的应用程序,该应用程序对 OData 进行异步查询。我使用以下通用形式进行查询:
DataServiceQuery<Entity> query = ourEntities.CreateQuery<Entity>("Entities");
entities.BeginExecute(QueryComplete, query);
不过,我在向这些查询添加过滤器时遇到了问题。使用 LINQ 似乎不是异步查询的选项,因此我尝试使用 这篇文章(尝试获取 Id 为 1 时的结果):
query.AddQueryOption("$filter", "Id eq 1");
如果我们从异步结果中获取 URL 并将其粘贴到浏览器中,它将正常工作并返回预期结果。但是,尝试评估查询结果似乎总是会导致没有消息或内部堆栈跟踪的 NotSupportedException。
理想情况下,我希望能够使用 LINQ,就像 Scott Hanselman 在他关于 OData 的 博客文章中所做的那样。如果这不是异步数据检索的选项,我如何实现查询过滤?
I am working on an application for Windows Phone 7 that makes asynchronous queries to OData. I use the following general form for the query:
DataServiceQuery<Entity> query = ourEntities.CreateQuery<Entity>("Entities");
entities.BeginExecute(QueryComplete, query);
I am having trouble adding filters to these queries, though. Using LINQ did not seem to be an option for asynchronous queries, so I tried adding OData filters using the AddQueryOption method mentioned in this article (trying to get results for when the Id is 1):
query.AddQueryOption("$filter", "Id eq 1");
If we take the URL from the async result and paste it into a browser, it works properly and returns the expected result. However, attempting to evaluate the result of the query always seems to result in a NotSupportedException with no message or inner stack trace.
Ideally, I'd like to be able to use LINQ, like Scott Hanselman did in his blog post about OData. If that is not an option for asynchronous data retrieval, how can I achieve filtering on the query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前Windows Phone 7 平台上的LINQ 支持是有限的。以前的 WCF 数据服务客户端旨在尝试哪些对我们的用户有效,哪些无效,但它有其局限性。有关更多详细信息,请参阅此博客文章:http://blogs.msdn.com/b/astoriateam/archive/2010/09/27/wcf-data-services-client-library-and-windows -phone-7-next-steps.aspx
一般来说,我建议您使用 BeginExecute 方法,并手动构造 URL,而不使用 DataServiceQuery 类,正如上面博客中所述,该方法在首次正式发布。
Currently the LINQ support on the Windows Phone 7 platform is limitted. The previous WCF Data Services client was meant to try what would work and what would not work for our users, but it has its limitations. See this blog post for more details: http://blogs.msdn.com/b/astoriateam/archive/2010/09/27/wcf-data-services-client-library-and-windows-phone-7-next-steps.aspx
In general I would suggest you use the BeginExecute method instead and construct the URL manually without the use of DataServiceQuery class, which as noted in the above blog will not be available in the first official release.