Is it possible to use Except()
for two List's that have two different classes but a common field? I have List<User1>
and List<User2>
collections. They have different properties except Id column and I want to find the different records between them using this Id column. I'm trying to use List<>.Except()
but I'm getting this error:
The type arguments for method 'System.Linq.Enumerable.Except(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Here's what I'm trying:
List<User1> list1 = List1();
List<User2> list2 = List2();
var listdiff = list1.Except(list2.Select(row => row.Id));
What am I doing wrong?
Enumerable.Except()
method. – Outlander