WCFDataServicesの2011年3月のCTP2とEntityFramework4 Code Firstを使用していますが、多くの問題が発生しています。私が抱えている問題は、サポートされていない「内部クエリ」に関連しています。
たとえば、サービス側にAuctionオブジェクトがあり、Auctionオブジェクトに0以上の入札を添付できます。ここで、クライアント側でこのクエリを実行して、現在の最高入札額(オークションオブジェクト)を見つけたいと思いました。
a.Bids.OrderByDescending(b => b.Amount).First().Amount
入札がない場合、これが失敗するという事実を無視してください。このクエリを実行すると、このエラーが発生します
The expression [10007].Bids.OrderByDescending(b => b.Amount).First().Amount is not supported.
だから私はこのロジックをサービス側に置くと思いました。クライアントからこのようにこのメソッドを呼び出します(これもオークションです)
a => _auctionContext.GetHighestBid(a.Id).First().Amount
再びエラーが発生します
The expression value(UI.AuctionService.AuctionContext).GetHighestBid([10007].Id).First().Amount is not supported.
私の質問は、なぜこれが起こっているのかということです。使用しているWCFデータサービスのバージョンが原因ですか?これらの問題は最新リリースで解決されていますか?
ありがとう
サチン
編集
_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);
}