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.
I've found a site listing the unsupported linq methods
http://msdn.microsoft.com/en-us/library/ee622463.aspx#unsupportedMethods
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
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!
精彩评论