Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

Group By Using Linq

I have the below object  List<Employees>
EmployeeID
Name
Designation
DOB
DOJ
Department


How do I use linq to group by the output like below

Designation      NoOfEmployees
Sales                   250
Marketing          100
Finance               25
HR                       15
0
Varshini S
Asked:
Varshini S
  • 2
1 Solution
 
Fernando SotoCommented:
Hi Rubha;

Are you wishing to group on Designation or Department?
0
 
Varshini SAuthor Commented:
Department
0
 
Fernando SotoCommented:
Hi Rubha;

This should give you what you need.

List<Employees> empList = new List<Employees>();
// ... List gets filled


var results = from emp in empList
              group emp by emp.Department into deptGroup
              select new
              {
                  Designation = deptGroup.Key,
                  NoOfEmployees = deptGroup.Count()
              };

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now