这是我写的第一个Linq 语句。写的比较慢。因为经常写sql现在写Linq 总是感觉不顺手。
不说了,下面就是我的一个Linq语句。
获得每组的记录数:
var b
=
from a
in
List1
let pcount = List2.Where(s => s.CenterId == a.CenterId).Count()
where a.CenterId != 0
select new
{
groupID = 1 ,
CenterID = a.CenterId,
lal = a.Latitude,
lo = a.Longitude,
isHave = a.HasData,
countC = pcount
};
let pcount = List2.Where(s => s.CenterId == a.CenterId).Count()
where a.CenterId != 0
select new
{
groupID = 1 ,
CenterID = a.CenterId,
lal = a.Latitude,
lo = a.Longitude,
isHave = a.HasData,
countC = pcount
};
获取组中记录最大的
var c
=
from d
in
b
group d by d.groupID into f
let e = f.Max(d => d.countC)
from row in f
where row.countC == e
select row;
group d by d.groupID into f
let e = f.Max(d => d.countC)
from row in f
where row.countC == e
select row;
读取数据
if (c.Count() > 0)
{
double a = c.ToList()[0].lal;
}
{
double a = c.ToList()[0].lal;
}