一个简单的LINQ问题:Group by
DataTable中的表结构是这样的:
ID Name ACount BCount CCount Date,Alarm
其中:Alarm是布尔型,
想得到如下结果:
Select ID,Name,Sum(ACount),Sum(BCount),Sum(CCount),Min(date),Alarm From Tbl
上面的结果中,只有被Group by的行中有一个Alram = true,结果集中就为True。
请问LINQ怎么写?
------解决方案--------------------
少写符号拉,呵呵
var tmpResult = from c in Tbl
group c by
new { c.ID,
c.Name
}
into d
select new { d.Key,
summ_ACount = d.Sum(p=>p.ACount),
summ_BCount= d.Sum(p=>p.BCount),
summ_CCount= d.Sum(p=>p.CCount),
min_date = d.Min(p=>p.date),
d.Any(p=>p.Alarm)
};