C# linq group by
c# by group LinQ
2023-09-14 09:16:28 时间
好久不用,忘了 记一下
//get data from db
List<ModelClass> source = new List<ModelClass>();
//单一条件分组
var sc1 = from sf in source
group sf by sf.Name;
//多个条件分组
var sc2 = from sf in source
group sf by new { sf.Name,sf.Price,sf.Amount}
into g
select new
{
Name= g.Key.Name,
Price= g.Sum(p=>p.Price),
Amount = g.Sum(p=>p.Amount)
};
//多个条件分组,并返回新的对象
var sc3 = from sf in source
group sf by new { sf.Name }
into g
//select new { Name = g.Key.Name, Price = g.Sum(p => p.Price), Amount = g.Sum(p => p.Amount) };
select new ModelClass()
{
Name = g.Key.Name,
Price =g.Sum(p=>p.Price),
Number = g.Sum(p=>p.Number),
};
};
var cls = from x in db.TableNames.Select(x => x.type).Distinct().ToList()
select new { account = x?.Trim()
var cls = from x in db.TableNames.Select(x=>x.Type).Distinct().ToList()
group x by new {x}
into g
select new {account=g.Key};
相关文章
- DirectX 3D 之C#开发
- c#使用XSLT将xml文档转换为html文档
- [C#] 常用工具类——应用程序属性信息访问类
- [C#] c# 验证手机号码 最新的17手机号
- 《C#高级编程》学习笔记----c#内存管理--栈VS堆
- C#.NET常见问题(FAQ)-如何输出带选项的MessageBox,YESNO
- 【MySQL】in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
- c# Mutex 互斥锁
- C# 创建线程的简单方式:异步委托 .
- C# 上传下载ftp(支持断点续传)
- C#中三种定时器对象的比较
- C# 希尔排序
- Atitit. C# java 的api 目录封装结构映射总结
- paip.分布式应用系统java c#.net php的建设方案
- C# 循环的中断——Break、continue、return
- C#MUD英雄大作战二、乔峰篇(副源码文件连接)
- [ VB ] If 运算符 [ C# ] 条件运算符 (?:)
- C#+无unsafe的非托管大数组(large unmanaged array in c# without 'unsafe' keyword)
- C#开发的OpenRA的游戏主界面怎么样创建3
- C#日期格式及其运算
- 【UiPath2022+C#】UiPath If条件语句