var grouped = Mains.GroupBy(l => l.ContactID); var ids = grouped.Select(g => g.Max(x => x.Id)); var result = grouped.Where(g => ids.Contains(g.Id));