0

hi guys i'm trying to get a full outer join from 2 tables

EX:

Table_A 
--------
_a
_c

Table_B
------
_a
_b

Result should be

Table_C
-------
_a
_b
_c

but i don't seem to get the actual result

this is what i've done

IEnumerable<string> leftOuter1 = (from watcher in _watchers
                                     join attendee in attendees on watcher equals attendee into set
                                     from attendee in set.DefaultIfEmpty()
                                     select attendee);

    IEnumerable<string> rightOuter1 = (from attendee in attendees
                                       join watcher in _watchers on attendee equals watcher into set
                                      from watcher in set.DefaultIfEmpty()
                                      select watcher);


    IEnumerable<string> participants1 = leftOuter.Union(rightOuter);

In _watchers i have value "_a".

In attendees values "_a" and "_b".

The firs result is _a but the second is _a, null. What am i doing wrong here?

Thank you

1 Answers1

1

you can see this

var firstNames = new[]    {
new { ID = 1, Name = "John" },
new { ID = 2, Name = "Sue" },    };

var lastNames = new[]
{
new { ID = 1, Name = "Doe" },
new { ID = 3, Name = "Smith" },
};
var leftOuterJoin = from first in firstNames
                join last in lastNames
                on first.ID equals last.ID
                into temp
                from last in temp.DefaultIfEmpty(new { first.ID, Name =       default(string) })
                select new
                {
                    first.ID,
                    FirstName = first.Name,
                    LastName = last.Name,
                };
var rightOuterJoin = from last in lastNames
                 join first in firstNames
                 on last.ID equals first.ID
                 into temp
                 from first in temp.DefaultIfEmpty(new { last.ID, Name =     default(string) })
                 select new
                 {
                     last.ID,
                     FirstName = first.Name,
                     LastName = last.Name,
                 }; var fullOuterJoin = leftOuterJoin.Union(rightOuterJoin);

see LINQ - Full Outer Join

Community
  • 1
  • 1