0
我想寫一個查詢來獲取與該部門相關員工的不同部門和數量(計數),但我無法找到確切的查詢在LINQ:集團按部門,並得到</p> <p>目前在該部門的員工人數
var empname = new List<EmpName>();
var empadd = new List<EmpAddress>();
var empsal = new List<EmpSalary>();
var empdep = new List<EmpDepartment>();
empdep.Add(new EmpDepartment { EmployeeID = 101, Department = "CIV" });
empdep.Add(new EmpDepartment { EmployeeID = 105, Department = "CIV" });
empdep.Add(new EmpDepartment { EmployeeID = 106, Department = "CIV" });
empdep.Add(new EmpDepartment { EmployeeID = 102, Department = "AEI" });
empdep.Add(new EmpDepartment { EmployeeID = 107, Department = "AEI" });
empdep.Add(new EmpDepartment { EmployeeID = 103, Department = "IES" });
empdep.Add(new EmpDepartment { EmployeeID = 202, Department = "IES" });
empdep.Add(new EmpDepartment { EmployeeID = 203, Department = "IES" });
empdep.Add(new EmpDepartment { EmployeeID = 104, Department = "PIE" });
empdep.Add(new EmpDepartment { EmployeeID = 208, Department = "PIE" });
var results = (from d in empdep
group d.Department by d.EmployeeID into g
select new EmpDetails
{
Department = g.Key.ToString(),
DeptCount = g.Count()
}).ToList();
顯示你已經嘗試過 –
編輯你的問題(不在評論中) –