3

私はこのクエリを持っています:

return (from r in this.Requests where r.Status == "Authorised" from i in r.Items select i).Sum(i => i.Value);

私は今それを好むので、それをラムダに変換しようとしました。

var sum = Requests.Where(x=>x.Status == "Authorised").Select(x=>x.Items).Sum(x=>x.Value);--> そして、ここにValueアイテムがありません。理由はありますか?

4

1 に答える 1

5

SelectManyの代わりにが必要ですSelect。クエリは基本的に次と同等です。

return this.Requests
           .Where(r => r.Status == "Authorised")
           .SelectMany(r => r.Items)
           .Sum(i => i.Value);

元のクエリも複数行でより明確になることに注意してください...

于 2012-12-05T10:48:57.663 に答える