LINQ TO DataSet: Multiple group by on a data table

前端 未结 1 2005
生来不讨喜
生来不讨喜 2020-12-09 12:01

I am using Linq to dataset to query a datatable. If i want to perform a group by on \"Column1\" on data table, I use following query

var groupQuery = from ta         


        
相关标签:
1条回答
  • 2020-12-09 12:14

    You should create an anonymous type to do a group by multiple columns:

    var groupQuery = from table in MyTable.AsEnumerable()
    group table by new { column1 = table["Column1"],  column2 = table["Column2"] }
          into groupedTable
    select new
    {
       x = groupedTable.Key,  // Each Key contains column1 and column2
       y = groupedTable.Count()
    }
    
    0 讨论(0)
提交回复
热议问题