Using C# and LINQ, I am trying to join lists gained from searching two seperate tables. Let's say I have two tables that I am pulling different details for different items.
var _listOne = await _tableOne.Select( x => new
{
Name = x.Name,
ID = x.ID,
}).ToArrayAsync();
var _listTwo = await _tableTwo.Select( x => new
{
Name = x.Name,
Leader = x.Leader,
Score = x.Score
}).ToArrayAsync();
Note this is generalized information, I have much more fields I grab and a lot of filters for each set of the list pertaining to certain conditions.
When I try and join these two lists, I lose a few records and I think it's because of how the mapping works with .Join().
So, it's setup like:
var _joinedLists = _listOne.Join(_listTwo,
item => item.Name,
details => details.Name,
(item, details) => new
{
itemName = item.Name,
ID = item.ID,
leaderName = details.Leader,
score = details.Score
}).OrderByDescending(x => x.ID).ToArray();
Let's say some record named "A" is in _tableOne, but "A" is not in _tableTwo, it does not join "A" in the list of _joinedLists, it leaves it out.
The main goal is I want to keep all records of _listOne even if some related record is not in _listTwo in my _joinedLists.
Is this how .Join() is suppose to work, and is there a way around this? I've looked at Union, but it seems to do that you have to have the same fields (or I suppose return types) for each of them and for my purpose that will not work. Tried googling around for this issue, but could not find anything other than Union/Concat (but like I said it does not work for my purpose).
Thanks.