I have a List
of Document
objects. The Document
class has many properties but only two are relevant here, DocumentLinkId
and UploadedOnDate
.
What I want to do is filter the list down so there are no two Document
objects with the same DocumentLinkId
. When there is more than one Document
object with a particular DocumentLinkId
I want to keep the one with the latest UploadedOnDate
.
My initial inclination was to do something like this:
myDocumentsList.Distinct(d => d.DocumentLinkId).Max(d => d.UploadedOnDate);
But Distinct()
doesn't take a predicate. Is there a way to do this with LINQ?