Using Group By LINQ C#
Look how simple is write the follow SQL Query in LINQ C#:
With SQL:
select city from students
group by city
order by cityNow in LINQ C#:
from student in Students
    group student.City by student.City into StudentGroup
    orderby StudentGroup.Key
    select StudentGroup.KeyEasy Right?
But I burned my brain to learn it.. LOL             
Written by Samuel Diogo
Related protips
2 Responses
 
LINQ was my favorite feature when I was working on the .NET platform. Glad to see that the demise of Linq2Sql was overstated. :)
over 1 year ago
·
 
Actually I more like programmer syntax aka
Students.GroupBy(g => g.City).OrderBy(o => o.Key).Select(s => s.Key)It was more easier to learn and I needn't to switch my brain into more likely sql syntax :)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Sql 
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#

 
 
 
