I am using the March 2011 CTP2 of WCF Data Services and Entity Framework 4 Code First and am having a lot of problems with it. The problems I am having relate to "inner queries" not being supported.
For example, on my services side I have an Auction object, an Auction object can have attached to it 0 or more bids. Now, on my client side I wanted to execute this query to find the current highest bid (a being an Auction object).
a.Bids.OrderByDescending(b => b.Amount).First().Amount
Ignore the fact that this will fail if there are no bids. I get this error when I run this query
The expression [10007].Bids.OrderByDescending(b => b.Amount).First().Amount is not supported.
So I thought I would put this logic in the service side. From the client I call this method thus (again a is an Auction)
a => _auctionContext.GetHighestBid(a.Id).First().Amount
I again get an error
The expression value(UI.AuctionService.AuctionContext).GetHighestBid([10007].Id).First().Amount is not supported.
My question is, why is this happening? Is it because of the version of WCF Data Services that I am using? Are these issues resolved in the latest release?
Thanks
Sachin
Edit
_auctionOrderings = new Dictionary<string, Func<IQueryable<Auction>, bool, IOrderedQueryable<Auction>>>
{
{"Ends", Utils.CreateOrderingFunc<Auction, DateTime?>(a => a.Ends)},
{"CurrentPrice", Utils.CreateOrderingFunc<Auction, decimal>(a.Bids.OrderByDescending(b => b.Amount).First().Amount)},
{"StartingPrice", Utils.CreateOrderingFunc<Auction, decimal>(a => a.StartingPrice)}
};
public static Func<IQueryable<T>, bool, IOrderedQueryable<T>> CreateOrderingFunc<T, TKey>(Expression<Func<T, TKey>> keySelector)
{
return
(source, ascending) =>
ascending
? source.OrderBy(keySelector)
: source.OrderByDescending(keySelector);
}
Unfortunately not supported due to the nature of the protocol. Here's a list of things you can't do.
http://msdn.microsoft.com/en-us/library/ee622463.aspx
My recommendation is to create a service method to do what you want to do.