Using Linq to find duplicates but get the whole record

后端 未结 2 2106
野性不改
野性不改 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:09

    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

提交回复
热议问题