2012-05-28 181 views
2

給出下面的查詢LINQ集團通過SUM

Dim Query = From c In DB.Crt _ 
         Where c.Member.Locked = False _ 
         And c.Member.Verified = True _ 
         And c.Ct > 0 _ 
         Order By c.Ct Ascending _ 
         Select New With {.MemberID = c.MemberID, _ 
             .Ct = c.Ct} 

我怎樣才能組由c.ct的SUM?

像​​

+0

您應該運行基於一些屬性總和法,有什麼相關的屬性(看來你的ID是唯一的,所以總結在不同的ID是沒有意義的)。 –

+0

不錯!現在我有兩個問題! – OrElse

+1

首先想想什麼是相關屬性運行求和方法,然後編輯你當前的問題。 –

回答

1

試試這個:

Dim Query = 
    From c In DB.Crt _ 
    Where c.Member.Locked = False _ 
    And c.Member.Verified = True _ 
    And c.Ct > 0 _ 
    Order By c.Ct Ascending _ 
    Group c.Ct By Key = c.MemberID Into Cts = Group _ 
    Select New With { .MemberID = Key, .Ct = Cts.Sum() }