LINQ Group by SUM

2019-05-26 17:53发布

Given the following query

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}

how can i group by SUM of the c.ct?

something like SUM OF(c.Ct) > 0

1条回答
孤傲高冷的网名
2楼-- · 2019-05-26 18:23

Try this:

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() }
查看更多
登录 后发表回答