【发布时间】:2014-04-13 12:20:57
【问题描述】:
我有一个大型数据库,我需要通过 groupby 来查找每个 Customer 的计数。这是我的查询:
var statisticList = (from item in Connection.DBConnection.TBStatistics
where item.Date >= startDate && item.Date <= endDate
group item by item.Customer into grp
where grp.Count() > 1
select new
{
Customer = grp.Key,
Count = grp.Count(),
}).ToList();
每个客户都有一些其他属性,例如Id、PhoneNumber、Address 和...。要从我的表中访问statisticList 中每个项目的详细信息:
foreach (var Cus in statisticList)
{
var allPlateDetail = (from item in Connection.DBConnection.TBStatistics
where item.Customer == Cus.Customer &&
item.Date >= startDate && item.Date <= endDate
select item).ToList();
//More Code...
}
但是速度很慢!
我希望statisticList 中的每个项目都有Id 以快速找到我数据库中的记录。这可能吗?
或者有没有办法在statisticList 中拥有所有这些属性?像列表中的子列表?
【问题讨论】: