using System.Collections.Generic;
public string ExternalDisplayId
public string Application
public DateTime CreateDate
class ApplicationExternalIDComparer : IEqualityComparer<SomeType>
public bool Equals(SomeType x, SomeType y)
if (Object.ReferenceEquals(x, y))
return (x.Application == y.Application && x.ExternalID == y.ExternalID);
public int GetHashCode(SomeType sometype)
return new { sometype.Application, sometype.ExternalID}.GetHashCode();
class ApplicationExternalDisplayIdComparer : IEqualityComparer<SomeType>
public bool Equals(SomeType x, SomeType y)
if (Object.ReferenceEquals(x, y))
if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null))
return (x.Application == y.Application && x.ExternalDisplayId == y.ExternalDisplayId);
public int GetHashCode(SomeType sometype)
return new { sometype.Application, sometype.ExternalDisplayId }.GetHashCode();
public static void Main()
Application = "Test", ExternalID = "1234", ExternalDisplayId = "111", CreateDate = new DateTime(2015,2,1)
Application = "Test", ExternalID = "1234", ExternalDisplayId = "5", CreateDate = new DateTime(2015,1,1)
Application = "Mono", ExternalID = "012", ExternalDisplayId = "90", CreateDate = new DateTime(2015,6,6)
Application = "Epic", ExternalID = "999", ExternalDisplayId = "78", CreateDate = new DateTime(2015,8,8)
Application = "Epic", ExternalID = "333", ExternalDisplayId = "78", CreateDate = new DateTime(2015,8,12)
Application = "Test", ExternalID = "345", ExternalDisplayId = "33", CreateDate = new DateTime(2015,2,1)
Application = "Test", ExternalID = "666", ExternalDisplayId = "33", CreateDate = new DateTime(2015,1,1)
var noduplicates = products.GroupBy(x => new {x.Application, x.ExternalDisplayId})
.Select(y => y.OrderByDescending(x => x.CreateDate).First())
.Distinct(new ApplicationExternalDisplayIdComparer())
.GroupBy(x => new {x.Application, x.ExternalID})
.Select(y => y.OrderByDescending(x => x.CreateDate).First())
.Distinct(new ApplicationExternalIDComparer());
foreach (var product in noduplicates)
Console.WriteLine("App:" + product.Application + " ExternalID:" + product.ExternalID + " ExternalDisplayID:" + product.ExternalDisplayId + " " + product.CreateDate.Date);