Linq left outer join

Gubi picture Gubi · Apr 21, 2011 · Viewed 11.2k times · Source

I ultimately what I needed is generic function which would take two datatable and and 2 tablekeys and return Joined datatable. So here is my first step to solve it.

How Can I write Linq example of following T-SQL example in VB?

SELECT * FROM
Table1
LEFT OUTER JOIN
Table2
ON Table1.key = Table2.key

Answer

Mikael Östberg picture Mikael Östberg · Apr 21, 2011

It would be something like this:

Dim JoinedResult = From t1 In Table1 
    Group Join t2 In Table2 
       On t1.key Equals t2.key 
       Into RightTableResults = Group 
    From t2 In RightTableResults.DefaultIfEmpty 
    Select t1.Prop1, 
       t2.Prop2        

I'm not a VB guy (anymore), but I think this would work.