title: C# - Left Outer Join lambda expression error
body: <p>I have the following tables:</p>
  
  <pre><code>Table1
  {
      Code   //string
      Desc   //string
  }
  
  Table2
  {
      Code   //string
      Value  //decimal?
  }
  </code></pre>
  
  <p>I need to Left Join the tables and for each Table2 Code/Value missing I want to show Code = Table1.Code, Desc = Table1.Desc and Value = null or blank.</p>
  
  <p>I tryied the following lambda expression:</p>
  
  <pre><code>      var result = Table1.GroupJoin(
                    Table2,
                    x =&gt; x.Code,
                    y =&gt; y.Code,
                    (x, y) =&gt; g
                        .Select(c =&gt; new { x.Code, x.Desc, Value = y.Value })
                        .DefaultIfEmpty(new { x.Code, x.Desc, Value = null }))
                        .SelectMany(g =&gt; g);
  </code></pre>
  
  <p>and got these errors:<br>
  <strong><em>The type arguments for method 'System.Linq.Enumerable.DefaultIfEmpty(System.Collections.Generic.IEnumerable, TSource)' cannot be inferred from the usage. Try specifying the type arguments explicitly.</em></strong></p>
  
  <p><strong><em>Cannot assign  to anonymous type property</em></strong></p>
  
  <p>So, I changed ...DefaultIfEmpty... Value = 0 }...</p>
  
  <p>and got these errors: 
  <strong><em>'System.Collections.Generic.IEnumerable' does not contain a definition for 'DefaultIfEmpty' and the best extension method overload 'System.Linq.Queryable.DefaultIfEmpty(System.Linq.IQueryable, TSource)' has some invalid arguments</em></strong></p>
  
  <p><strong><em>Instance argument: cannot convert from 'System.Collections.Generic.IEnumerable' to 'System.Linq.IQueryable'</em></strong></p>
  
  <p>Any idea to solve the errors?</p>