日期:2014-05-20  浏览次数:20832 次

求助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)
};