Linq分组查询,然后求某列的和
2个都是在执行 int use = .....这句的时候慢。
数据有最大有几百万条,但是现在blists里只有几万条的数据,查询速度就很慢了。这个有办法优化吗?
下面2种写法有没有区别?如果有那个执行效率较好(不考虑别的,只考虑得到use的结果)
var blist = from p in blists group p by new { p.roleid,p.oper_type} into g select new { g.Key.oper_type, sum_gold = g.Sum(p => p.gold), sum_coupon = g.Sum(p => p.coupon), sum_copper = g.Sum(p => p.copper) };int use = blist.Where(p => p.oper_type == 1).Sum(p => p.sum_gold);/////////////////////////////////////////////////var blist = from p in blists group p by p.oper_type into g select new { g.Key, sum_gold = g.Sum(p => p.gold), sum_coupon = g.Sum(p => p.coupon), sum_copper = g.Sum(p => p.copper) };int use = blist.SingleOrDefault(p => p.oper_type == 1).sum_gold;