If I understand you correctly, I had a similar problem.
Based on this post , I made this extension method
public static IEnumerable<T> Distinct<T>(this IEnumerable<T> source, Func<T, object> keyExtractor) { return source.Distinct(new KeyEqualityComparer<T>(keyExtractor)); }
which automatically generates the necessary implementation of IEqualityComparer for this lambda. In your case, this will allow you to use something like:
return Employees .SelectMany(e => e.PostList.Posts) .Distinct(postViewModel => postViewModel.ID) .ToList();
source share