Using Linq to find duplicates but get the whole record

后端 未结 2 2099
野性不改
野性不改 2021-02-15 00:36

So I am using this code

    var duplicates = mg.GroupBy(i => new { i.addr1, i.addr2 })
                    .Where(g => g.Count() > 1)
                          


        
2条回答
  •  不思量自难忘°
    2021-02-15 01:12

    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()});
    

提交回复
热议问题