Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Group By Using Linq

Posted on 2014-03-03
3
233 Views
Last Modified: 2016-02-10
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
Comment
Question by:Varshini S
  • 2
3 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39900634
Hi Rubha;

Are you wishing to group on Designation or Department?
0
 

Author Comment

by:Varshini S
ID: 39900663
Department
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39900685
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question