我需要对类似的记录进行排序,除了id之外,所有细节都相似,而不是更改另一条记录。下面是示例
INPUT
Id First Name Last Name Mobile Email
1 John B 9000000000 john@gmail.com
2 John B 9000000000 john@gmail.com
3 Swamy P 9999999999 abc@gmail.com
4 kelvin F 8888888888 def@gmail.com
OUTPUT
Id First Name Last Name Mobile Email
1|2 John B 9000000000 john@gmail.com
3 Swamy P 9999999999 abc@gmail.com
4 kelvin F 8888888888 def@gmail.com
根据上面的例子,类似的记录被合并为一个,除了唯一键,它具有由管道符号分隔的所有相似的唯一ID。
答案 0 :(得分:0)
您需要GroupBy: -
var result = list.GroupBy(x => new { x.FirstName, x.LastName, x.Mobile, x.Email })
.Select(x => new
{
Id = String.Join("|",x.Select(z => z.Id)),
FirstName = x.Key.FirstName
LastName = x.Key.LastName,
Mobile = x.Key.Mobile,
Email = x.Key.Email
});