So I am using this code
var duplicates = mg.GroupBy(i => new { i.addr1, i.addr2 })
.Where(g => g.Count() > 1)
You should use First()
instead of Key
:
var duplicates = mg.GroupBy(i => new { i.addr1, i.addr2 })
.Where(g => g.Count() > 1)
.Select(g => g.First());
It returns the first row of each duplicate groups
To get all values, you can use ToList()
on IGrouping
var duplicates = mg.GroupBy(i => new { i.addr1, i.addr2 })
.Where(g => g.Count() > 1)
.Select(g => new {g.Key, Values = g.ToList()});