Supported Linq for WCF Data Services

ぐ巨炮叔叔 提交于 2019-12-12 10:56:33

问题


I'm looking for the full list of supported linq extension methods that are compatible with WCF Data Services.

By trial and error I've found First( Func ) and Single( Func ) aren't supported, any others?

This gives me a pretty good idea of whats supported, I just don't know whats actually translated via the IQueryProvider.


回答1:


I've found a site listing the unsupported linq methods

http://msdn.microsoft.com/en-us/library/ee622463.aspx#unsupportedMethods




回答2:


First and Single are not supported for Silverlight because Silverlight requires all networking be done async, but you can simulate it with code like this

NorthwindEntities context = new NorthwindEntities(new Uri("Northwind.svc", UriKind.Relative));
DataServiceQuery<Order> q = (DataServiceQuery<Order>)context.Orders.Take(1);
q.BeginExecute((IAsyncResult ar) =>
    {
        var o = ((DataServiceQuery<Order>)q).EndExecute(ar).First();
        txtOutput.Text = o.OrderID.ToString();
    }, null);

In this code you are requesting only one be sent over the network with the Take(1), and then once it is already on the client using First() or Single() to easily get the singleton reference.

There is no definitive list of supported Linq operators available that I know of.

-jeff




回答3:


Those finding of yours are interesting indeed - especially if you check out the MSDN docs Querying the Data Service (WCF Data Services).

In the first paragraph, the docs state:


A query is executed in the following scenarios:

  • When results are enumerated implicitly, such as:
    • When a property on the DataServiceContext that represents and entity set is enumerated, such as during a foreach (C#) or For Each (Visual Basic) loop.
    • When the query is assigned to a List collection.
    • When the Execute or BeginExecute method is explicitly called.
    • When a LINQ query execution operator, such as First or Single is called.

A few lines further down, there's a yellow "Note" box stating:

Note

The set of queries expressible in the LINQ syntax is broader than those enabled in the representational state transfer (REST)-based URI syntax that is used by data services. A NotSupportedException is raised when the query cannot be mapped to a URI in the target data service.

Unfortunately, I can't find any explicit list of which operators in the LINQ syntax are or aren't supported by WCF Data Services - a glaring lack in the documentation!



来源:https://stackoverflow.com/questions/2775473/supported-linq-for-wcf-data-services

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