Following situation: There exists an array acting as crosstable (mergeSet). Additionally there exists a set of target values and a set of source values. The source values can be joined with the target values via the crosstable. - But how is it possible to express an outer join of, e.g., the targetSet against the other tables by using only one LINQ expression? Currently I found only solutions using multiple LINQ expressions (i.e. an inner join of targetSet+mergeSet+sourceSet, then the pure left outer part and finally a concatenation of the innerJoinResult and the outerPart).
var mergeSet = new[]
{
new KeyValuePair<int, int>(3, 4),
new KeyValuePair<int, int>(5, 6)
};
var targetSet = new[] { 1, 3, 5, 7 };
var sourceSet = new[] { 4, 6 };
var innerJoinResult =
from mergeItem in mergeSet
join sourceItem in sourceSet on mergeItem.Value equals sourceItem
join targetItem in targetSet on mergeItem.Key equals targetItem
group sourceItem by targetItem;
var outerPart =
from targetItem in targetSet
where !mergeSet.Any(mergeItem => mergeItem.Key == targetItem)
group 0 by targetItem; // Fill the right part with zero.
var outerJoinResult = outerPart.Concat(innerJoinResult);