title: Join Multiple Datatables in LINQ using Group Join
body: <p>I have five datatablas in one dataset. Now I need to join them all together. The point is, that some entries from table1 not have an entry in the other tables. So I need a left join or left outer join. In SQL it works like this:</p>
  
  <pre><code>SELECT *
  FROM TABLE1 LDC 
  LEFT JOIN TABLE2 LGDE ON LDC.KEY1 = LGDE.KEY2
  LEFT JOIN TABLE3 DEFI ON  LGDE.KEY3 = DEFI.KEY 4
  LEFT JOIN TABLE4 SETT ON DEFI.KEY5 = SETT.KEY6
  LEFT JOIN TABLE5 LST ON SETT.KEY7 = LST.KEY8
  </code></pre>
  
  <p>Now I rebuilt that statement with LINQ in my VB.NET code. In some other posts I figured out, that I have to use <code>DefaultIfEmpty()</code>. But I could not get this to work. So here's my Code. (We're on the .NET Framework 3.5)</p>
  
  <pre><code>Dim result = From ldc In TABLE1
                 Group Join lgde1 In TABLE2 On ldc.Field(Of String)("KEY1") Equals lgde1.Field(Of String)("KEY2") Into g = Group
               From lgde In g.DefaultIfEmpty()
                 Group Join defi1 In TABLE3 On lgde.Field(Of Decimal?)("KEY3") Equals defi1.Field(Of Decimal?)("KEY4") Into g2 = Group
               From defi In g2.DefaultIfEmpty()
                 Group Join sett1 In TABLE4 On defi.Field(Of Decimal?)("KEY5") Equals sett1.Field(Of Decimal?)("KEY6") Into g3 = Group
               From sett In g3.DefaultIfEmpty()
                 Group Join lst1 In TABLE5 On sett.Field(Of Decimal?)("KEY7") Equals lst1.Field(Of Decimal?)("KEY8") Into g4 = Group
               From lst In g4.DefaultIfEmpty()
  </code></pre>
  
  <p>(The Select Part works, thats why I did not post it)</p>
  
  <p>I always get the following error: </p>
  
  <p>The value mustn't be NULL. Parametername: row in System.Data.DataRowExensions.Field[T](Datarow, row, String columnName) on Line 336.</p>
  
  <p>Any idea why it's not working?</p>
  
  <p>Regards</p>