C# linq sum 效率问题,求大神!!!
1、 var lastYearMonth = from p in
(from r in queLastYearMonthData.AsEnumerable()
group r by new { jxbm = r.Key } into g
select new { g.Key, count = g.Sum(x => x.count),sale=g.Sum(x=>x.sale), jj = (g.Sum(x => x.sale) / (ct = g.Sum(x => x.count) == 0 ? 1 : g.Sum(x => x.count))) }).AsEnumerable()
where p.jj >= Convert.ToDecimal(prices[j]) && p.jj < Convert.ToDecimal(prices[j + 1])
select p;
2、 decimal lastYearMonthCount_TB = lastYearMonth.Sum(x=>x.count);
3、 decimal lastYearMonthSale_TB = lastYearMonth.Sum(x => x.sale);
问题如下:
第一句查询筛选 剩余 2K 多条数据,查询很快,不足1s
第二、三条语句实现 sum()时,效率很慢,2s左右
求解决方案!!!