我正在研究这个LINQ查询。我希望结果列表根据EMailAddress1字段返回一个包含重复项的记录列表,并按EMailAddress1字段分组。
例如:
等
对此有何建议?谢谢。
var contacts = (from c in xrm.ContactSet
where c.StateCode != 1
orderby c.EMailAddress1, c.CreatedOn
descending select new {
c.FirstName,
c.LastName,
c.EMailAddress1,
c.ContactId,
c.CreatedOn }).ToList();
答案 0 :(得分:0)
根据您之前的查询:
var duplicatedEmails = (from c in contacts
group c by c.EMailAddress1 into g
where g.Count() > 1
select g.Key).ToList();
var duplicatedContacts = contacts.Where(c => duplicatedEmails.Contains(c.EMailAddress1));