fsgz6w
Last Updated: March 02, 2016
·
15.59K
· samudiogo
Facebook

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 city

Now in LINQ C#:

from student in Students
    group student.City by student.City into StudentGroup
    orderby StudentGroup.Key
    select StudentGroup.Key

Easy Right?
But I burned my brain to learn it.. LOL

Say Thanks
Respond

2 Responses
Add your response

17571
Avatar

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 ·
17698
0 srapvxnxz8nfktm1fkf7vjn1v  drbm17nv vpqflq64fimp39orry 3qdtcp8z0u12gsuzxqhfv

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 ·