0

I have two tables

T1     T2
-------------
id1    id2
-----------
1      3
2      5
3
4

I want to get a outer join so that I get 1,2,3,4,5

I am using following Linq command

   var newList = (from i in T1
                   join d in T2
                   on i.id1 equals d.id2 into output
                   from j in output.DefaultIfEmpty()
                   select new {i.id}); 

The out put I get i 1,2,3,4 missing 5. How can I get it to give me newList 1,2,3,4,5 Help Please

J. Davidson
  • 3,297
  • 13
  • 54
  • 102

2 Answers2

2

There is no direct alternative to OUTER JOIN in LINQ. You have to solve it like this:

Within query you wrote only the i's that also exists in T2 because of the on i.id1 equals d.id2.

var result = T1.Select(item => item.id1).Union(T2.Select(item => item.id2));
Jan P.
  • 3,261
  • 19
  • 26
0

You could use Union like:

var result = T1.Union(T2);

You can refer to this C# linq union question

Community
  • 1
  • 1
Dietz
  • 578
  • 5
  • 14