c#linq去除重复项并将相同数据的数量字段值相加
这是执行前和执行后想要的效果
以下是用Sql语句实现的代码:
select goodsno, goodsspec,SUM([count]) as count from goods group by goodsno ,goodsspec
下面这个则是用Linq实现的代码:
var res = (from l in picModel group l by new { goodsno = l.GoodsNO, goodsSpec = l.SpecName, RecID = l.RecID, Position = l.Position } into g select new { goodsno = g.Key.goodsno, goodsSpec = g.Key.goodsSpec, count = g.Sum(c => c.Count), RecID = g.Key.RecID, Position = g.Key.Position }).ToList();
本文来自博客园,作者:沉迷编程的程序员,转载请注明原文链接:https://www.cnblogs.com/codeDevotee/p/7088579.html
欢迎各位找我代写程序,python、c#、web等都可以,加我请注明博客园微信:A15919195482