linqgroupby分组,并且sum求和,最后排序Orderby
写法
List<model> lstPFSelect = appdal.GetPlatformSelectWhere();
//省份
//1,linq to sql 写法
var listAddress = (from a in lstPFSelect
group a by new { a.Province,a.ProName} into g
//orderby new ComparerItem() { OrderIndex = b.Key., Id = b.Key.Id } descending
select new
{
Province=g.Key.Province,
groupby分组
ProName = g.Key.ProName,
OrderIndex = g.Sum(c => c.ProjectNum)
}).OrderByDescending(t => t.OrderIndex).ThenBy(t => t.Province);
---------------------------------------------------------------------------------------------------------------------
//省份
//2,labmda表达式写法
listAddress.GroupBy(t => t.Province)
.Select(g => new
{
Province= g.Sum(t => t.Province),
ProName = g.Sum(t => t.ProName),
OrderIndex = g.Sum(t => t.ProjectNum)
});
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论