c# linq查询

List<DeptInfo> deptList = (from emp in empList
                                where emp.Status == "在职"            //筛选“在职”员工     
                                orderby emp.DeptID ascending          //按“部门ID”排序
                                group emp by new                      //按“部门ID”和“部门名称”分组
                                {
                                    emp.DeptID,
                                    emp.DeptName
                                }
                                into g
                                select new DeptInfo()
                                {
                                    DeptID = g.Key.DeptID,
                                    DeptName = g.Key.DeptName,
                                    EmplayeeCount = g.Count(),          //统计部门员工数量
                                    WageSum = g.Sum(a => a.Wage),       //统计部门工资总额
                                    WageAvg = g.Average(a => a.Wage),   //统计部门平均工资
                                    EmplayeeList = (from e in g         //归集部门员工列表
                                                    select new Emplayee()
                                                    {
                                                        EmpID = e.EmpID,
                                                        EmpName = e.EmpName
                                                    }
                                                    ).ToList()
 
                                }).ToList();
 

 

 

 

var temp = (from a in student
                            from p in syncchip
                                //  join p in syncchip
                                //on c.id equals p.user_id
                                where a.class_id==index
                                orderby a.id
                                group a by new { a.id,a.name,a.className ,a.sex,a.head_img } into g

                            select new
                            {
                                stdent_id =g.Key.id,
                                name = g.Key.name,
                                className = g.Key.className,
                                sex = g.Key.sex,
                                head_img=g.Key.head_img,
                                cou = (from e in syncchip        
                                       where e.user_id == g.Key.id
                                       group e by e.user_id into b
                                       select new
                                       {
                                           cou = g.Count()
                                       }
                                       ).Count()                                
                            }).ToList();

                List<StudentClass> list = new List<StudentClass>();
                foreach (var i in temp)
                {
                    list.Add(new StudentClass {student_id =i.stdent_id,name=i.name,cou=i.cou ,className=i.className,sex=i.sex,head_img=i.head_img});
                }

c# linq查询

上一篇:Windows 相关


下一篇:c# 判断是否有网