title: LINQ left join + default if empty + anonymous type + group by
body: <p>I wonder what is the best solution for the given problem, simplified here:</p>
  
  <ol>
  <li><p>I have two locally stored sql tables which I want to join (left join) with Default If Empty property, then I need to group these data</p></li>
  <li><p>I don't want to check for (obj == null) before accessing obj.column, which will throw an error if join was no successful for a given row</p></li>
  </ol>
  
  <p>Data</p>
  
  <pre><code>LeftTable    RightTable    OUTPUT
   A B C        A B Z         A  B  C  Z
   1 1 1        1 1 5         1  1  1  5
   1 2 2        1 2 6         1  2  2  6
   5 6 7                      5  6  7 null
  </code></pre>
  
  <p>Code</p>
  
  <pre><code>var RightTable = from row in Source
                   where row.X &gt; 10
                   select new {        // anonymous type that I want to keep
                      A = row.AAA,
                      B = row.BBB,
                      Z = row.ZZZ
                   };
  
  var test = from left in LeftTable
             from right in RightTable
               .Where(right =&gt; right.A == left.A
                  &amp;&amp; right.B == left.B )
               .DefaultIfEmpty( /* XXXXX */ )   //&lt;-- this line is interesting
             group left by new {
               left.A
               left.B
               left.C
               right.Z  //&lt;-- this will throw null exception error
             } into g     //  but I don't want to change it to 
             select g;    //  Z = (right != null) ? right.Z : (string) null
  </code></pre>
  
  <p>Question: </p>
  
  <p>Can I fill an argument in DefaultIfEmpty with anything that I can dynamically get from this code?</p>
  
  <p>I know I can create a helper type like below and replace the anonymous type in RightTable select and use it inside default if empty like: </p>
  
  <pre><code>DefaultIfEmpty(new Helper())
  </code></pre>
  
  <p>but I dont want to do it as I have to deal with 20,30+ columns in real life scenario.</p>
  
  <pre><code>public class Helper {
      public string A,
      public string B,
      public string C
  }
  </code></pre>
  
  <p>Thanks a lot for your time if you read until here. Hope to get some solution here. 
  Thanks.</p>