我有兩個LINQ語句,我想將它們合併爲一個,但對於我的生活,我無法實現它。我不能讓分組在第一個語句中工作。 它抱怨TotalBuy
和TotalSell
屬性不存在,雖然不抱怨AmountTC
和AmountAUD
。LINQ JOIN + GROUP BY + SUM
這應該很簡單。有什麼想法嗎?
var itineraryItems =
from ii in this.ItineraryItemRecords
join t in this.TransactionRecords on ii.OperatorID equals t.
TransactionActor.OperatorID into g select new {
OperatorID = ii.OperatorID, TotalBuy = g.Sum(i = >ii.TotalBuy)
, TotalSell = g.Sum(i = >ii.TotalSell)
, PaidTC = (0 - (g.Sum(t = >t.AmountTC)))
, PaidAUD = (0 - (g.Sum(t = >t.AmountAUD)))
};
var itineraryItemz =
from i in itineraryItems group i by i.OperatorID into g select new {
OperatorID = g.Key, TotalBuy = g.Sum(i = >i.TotalBuy)
, TotalSell = g.Sum(i = >i.TotalSell)
, PaidTC = (0 - (g.Sum(i = >i.PaidTC)))
, PaidAUD = (0 - (g.Sum(i = >i.PaidAUD)))
};
作爲邊注,ItineraryItemRecords
和TransactionRecords
是由SubSonic
處理類類別。
這真的應該很簡單,所以任何幫助,將不勝感激。
問候, 約翰
@JohnBob - 我用c#標籤重新標記了您的問題,以便它可能會得到更多的注意,因爲沒有人回覆。 – dugas 2010-02-22 14:44:01