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; }

    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM