首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

linq to datatable group by sum的有关问题

2012-01-09 
求助linq to datatable group by sum的问题我有个datatableabcdea1 b1 c1 d1 1a2 b2 c2 d2 1a2 b2 c2 d2 1

求助linq to datatable group by sum的问题
我有个datatable 
a b c d e
a1 b1 c1 d1 1
a2 b2 c2 d2 1
a2 b2 c2 d2 1
a3 b3 c3 d3 1

想操作后返回一个datatable

a b c d e
a1 b1 c1 d1 1
a2 b2 c2 d2 2
a3 b3 c3 d3 1

当如何写呀?

这个是从逗号分隔符文件中读出来的。

小鸟不会linq,但知道linq可以这样做,请大虾教我,谢谢。

[解决办法]

C# code
var re = from t in datatable           group t by new {t.a,                         t.b,                         t.c,                         t.d} into g         select new {g.key,                     e=sum(g.e)};
[解决办法]
var q =
from p in db.Student
group p by new {p.a,p.b,p.c} into g
select new {
g.Key,
g.Sum(p => p.e)
};

热点排行