1、 按某一字段进行分组并返回每一组的记录数目
List<DbInfo> list = new List<DbInfo>()
{
new DbInfo(){ DbId=1,HostId=1 },
new DbInfo(){ DbId=2,HostId=1 },
new DbInfo(){ DbId=3,HostId=2 },
new DbInfo(){ DbId=4,HostId=2 }
};
var result = list.GroupBy(d => d.HostId);
var ee = result.Where(d => d.Key == 1).FirstOrDefault() == null ? 0 : result.Where(d => d.Key == 1).FirstOrDefault().Count();
Console.WriteLine(ee);
Console.ReadLine();