日期:2014-05-18 浏览次数:20971 次
void Main() { var dt=new DataTable(); dt.Columns.Add("medicID"); dt.Columns.Add("price"); dt.Columns.Add("num",typeof(int)); dt.Columns.Add("unit"); dt.Rows.Add("0001","1.2",10,"盒"); dt.Rows.Add("0001","1.2",15,"盒"); dt.Rows.Add("0002","14",15,"支"); dt.Rows.Add("0003","10",10,"盒"); dt.Rows.Add("0002","14",10,"盒"); var query=dt.AsEnumerable() .GroupBy(d=>new {medicID=d.Field<string>("medicID"),price=d.Field<string>("price"),unit=d.Field<string>("unit")}) .Select(g=>new{ medicID=g.Key.medicID, price=g.Key.price, num=g.Sum(d=>d.Field<int>("num")), unit=g.Key.unit }); }