Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
i want to display the count of number of employees by department wise.
i want to get the columns like "count, departmentname" .. by using the linq
i am having tables like EMP, Dept in my db.

Can anyone help me?
Posted
Updated 6-Dec-11 22:38pm
v3
Comments
Code 89 7-Dec-11 4:43am    
Post your code here...

C#
var Query = from p in DCDC.EMP.GroupBy(p => p.departmentname)
                        select new
                            {
                                count = p.Count(),
                                p.First().departmentname,
                            };



Hope it helps :)
 
Share this answer
 
v3
C#
var q = from c in dsEC09.Employee
        group c by c.DepartMent into g
        select new { g.Key, Count = g.Count() };

Mark as answer if its solved your problem
 
Share this answer
 
Refer to following link:
http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b[^]

Ex from link
C#
var categoryCounts =
        from p in products
        group p by p.Category into g
        select new { Category = g.Key, ProductCount = g.Count() };
 
Share this answer
 
Comments
ganesh_kanc 7-Dec-11 6:57am    
thank u vivek ..
 
Share this answer
 
Comments
ganesh_kanc 7-Dec-11 6:58am    
thank you man.. the links which were suggested by u helped me a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900