Grouping objects with LINQ in C#

A collegue of mine needed an algorithm to filter out duplicate objects in a List and count the total occurence of each distinct object. He used this query to get his results, it may be usefull to some of you.

 

myRoles = from c in allRoles 
group c.RoleId by new { c.PersonId, c.RoleTypeId }
into g
orderby g.Count() descending
select g;

 

Credits go to Roel Dieltjens

Tags:

Development

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Björn Bailleul

Web application engineer and developer interested in creating customer centric applications build for ease of use and efficiency. My experience goes from intranet applications to widely used service websites, product portfolios and e-commerce websites.

Specialties

C#, MVC, AJAX, ASP.NET, SQL Server, SQL Reporting Services, WCF, XML, HTML, JavaScript, CSS, Web Services, Scrum, ...

View Bjorn Bailleul's profile on LinkedIn

Month List