LINQ集团通过SUM(LINQ Group by SUM)

2019-09-17 13:56发布

考虑下面的查询

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}

我怎么能集团通过的SUM c.ct

类似SUM OF(c.Ct) > 0

Answer 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() }


文章来源: LINQ Group by SUM