Created
January 21, 2013 15:04
-
-
Save cleytonferrari/4586685 to your computer and use it in GitHub Desktop.
Usa o agrupamento para fazer um Distinct de objetos complexo, mais informações em http://stackoverflow.com/questions/489258/linq-distinct-on-a-particular-property
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Selecionando objetos distintos usando Linq | |
//Agrupando com uma propriedade | |
List<Pessoa> pessoasDistintas = todasAsPessoas | |
.GroupBy(p => p.Id) | |
.Select(g => g.First()) | |
.ToList(); | |
//Agrupando com varias propriedades | |
List<Pessoa> pessoasDistintas = todasAsPessoas | |
.GroupBy(p => new {p.Id, p.CorFavorita} ) | |
.Select(g => g.First()) | |
.ToList(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment