LINQ Group By with multiple parameters

后端 未结 2 1736
暗喜
暗喜 2021-02-04 06:28

I have a VB.NET application and want to do Group By on multiple columns.

Class Structure:

Public Class Person
   Public Property Name as         


        
2条回答
  •  情深已故
    2021-02-04 06:36

    Dim q1 = (From p In Repository.Table
                                Group p By p.CreatedDate.Year, p.CreatedDate.Month Into Group
                                Select New With {.Year = Year, .Month = Month, .Count = Group.Count()}).ToList
    

    Or

    Dim q2 = (From p In Repository.Table
                                Group p By key = New With {.Year = p.CreatedDate.Year, .Month = p.CreatedDate.Month} Into Group
                                Select New With {.Year = key.Year, .Month = key.Month, .Count = Group.Count()}).ToList
    

提交回复
热议问题