I have 2 list:
List1:
ID
1
2
3
List2:
ID Name
1 Jason
1 Jim
2 Mike
3 Phil
I like to join both of these but get only the first record from list2 for a given ID:
The end result would be
ID Name
1 Jason
2 Mike
3 Phil
I tried the following but was not successful:
var lst = (from lst1 in list1
join lst2 in list2
on lst1.ID equals lst2.ID).ToList().First();
You can get this result with what the 101 LINQ Samples calls “Cross Join with Group Join”. Combine that with
First()to get just one item from the group.Example: http://ideone.com/V0sRO