zoukankan      html  css  js  c++  java
  • 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; }
    
        }
  • 相关阅读:
    DBAccess
    业务耗时及数组
    QB资料学习.01
    格式化参数
    日志记录.02_线程处理
    nginx 开启gzip
    js 变量提升和函数提升
    js 深拷贝 vs 浅拷贝
    js 伪数组 转 数组
    js 对象原型和原型链
  • 原文地址:https://www.cnblogs.com/ShenJA/p/12699073.html
Copyright © 2011-2022 走看看