Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello I want Convert Below Code To Linq & Lambda Please Help Me

SQL
select Section, COUNT(*) from HealthyMap GROUP BY Section


regards
yarian

What I have tried:

In Entity FrameWork By C#
Linq To Entity
Posted
Updated 12-Aug-16 21:23pm

1 solution

try this

C#
var result = YourList.GroupBy(k => k.Section).Select(grp => new { Section = grp.Key, Count = grp.Count() }).ToList();
 
Share this answer
 
Comments
Garth J Lancaster 13-Aug-16 3:33am    
I was a bit worried about the .ToList(), thinking that a dictionary might have been better - but then I realised you're creating and returning a list of anonymous objects with Section and Count properties - nice :-)
Karthik_Mahalingam 13-Aug-16 3:50am    
:-)

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