随笔 - 44  文章 - 1  评论 - 3  阅读 - 47676

EF+Linq分组 多条件

复制代码
public class Program
    {
        static void Main(string[] args)
        {
            var list = new List<ceshi>()
            {
                new ceshi{Name="掌声",ID=1,Pid=10,paix=1 },
                new ceshi{Name="李四",ID=1,Pid=11,paix=2 },
                new ceshi{Name="掌声",ID=1,Pid=12,paix=3 },
                new ceshi{Name="掌声",ID=2,Pid=13 ,paix=4},
                new ceshi{Name="李四",ID=2,Pid=14 ,paix=5},
                new ceshi{Name="掌声",ID=2,Pid=15 ,paix=6},
                new ceshi{Name="李四",ID=7,Pid=16 ,paix=7},
                new ceshi{Name="王五",ID=7,Pid=16 ,paix=7},
            };
            //多条件分组
            var sums2 = from emp in list
                        where emp.Name!= "王五"
                        orderby emp.paix
                        group emp by new { emp.Name, emp.ID } into g
                        select new { Peo = g.Key.Name,pen=g.Key.ID, Count = g.Count() };
            foreach (var employee in sums2.ToList())
            {
                Console.WriteLine(employee.Peo+":"+employee.pen + ": " + employee.Count);
            }
        }
    }


     public class ceshi
    {
        public string Name { get; set; }
        public int ID { get; set; }
        public int Pid { get; set; }

        public int paix { get; set; }

    }
复制代码

 

posted on   程铭  阅读(931)  评论(0编辑  收藏  举报
编辑推荐:
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示