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 2020-04-14 16:51  程铭  阅读(918)  评论(0编辑  收藏  举报