LINQ TO DataSet:数据表上的多个分组依据 [英] LINQ TO DataSet: Multiple group by on a data table

查看:25
本文介绍了LINQ TO DataSet:数据表上的多个分组依据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Linq to dataset 来查询数据表.如果我想对数据表的Column1"执行分组,我使用以下查询

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 table in MyTable.AsEnumerable()
group table by table["Column1"] into groupedTable

select new
{
   x = groupedTable.Key,
   y = groupedTable.Count()
}

现在我想对两列Coulmn1"和Column2"执行分组.谁能告诉我语法或给我一个解释数据表上多个分组依据的链接??

Now I want to perform group by on two columns "Coulmn1" and "Column2". Can anybody tell me the syntax or provide me a link explaining multiple group by on a data table??

谢谢

推荐答案

您应该创建一个匿名类型来按多个列进行分组:

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

这篇关于LINQ TO DataSet:数据表上的多个分组依据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆