title: Group By Department and get number of employees present in that department
body: <p>I am trying to write a query to get distinct department and number of Employees associated with that department(count)</p>
  
  <p>But I'm not able to find exact query in linq:</p>
  
  <pre><code>var empname = new List&lt;EmpName&gt;();
  var empadd = new List&lt;EmpAddress&gt;();
  var empsal = new List&lt;EmpSalary&gt;();
  var empdep = new List&lt;EmpDepartment&gt;();
  
  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();
  </code></pre>