LINQ集团由SUM

时间:2012-05-28 16:31:48

标签: vb.net linq linq-to-sql group-by

给出以下查询

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进行分组

类似于SUM OF(c.Ct) > 0

1 个答案:

答案 0 :(得分: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() }