title: C# LINQ Multiple GroupJoin using Lambda Syntax
body: <p>I have 3 tables that I am trying to combine them together using left joins. In my application, all LINQ expressions are in query-chain format (lambda expressions).</p>
  
  <p>I am trying to figure out how to accomplish this query using LINQ;</p>
  
  <p>This is my SQL query;</p>
  
  <pre><code>select i.INVOICE_NUMBER, ic.CustomerName, o.BusinessUnit
  from Invoices_Daily as i
  left join intercompany as ic on i.customer_number = ic.customernumber
  left join ordertypes as o on i.LINE_ORDERTYPE = o.OrderType
  </code></pre>
  
  <p>I have tried combining the <code>GroupJoin</code> as follows;</p>
  
  <pre><code>var commissions = data
      .GroupJoin(genericNameList,
          d =&gt; d.CUSTOMER_NUMBER,
          g =&gt; g.CustomerId,
          (d, g) =&gt; new { d, generic = g.FirstOrDefault() })
      .GroupJoin(intercompanies,
          dd =&gt; dd.d.CUSTOMER_NAME,
          i =&gt; i.CustomerId,
          (d, i) =&gt; new { data = d.d, intercompanies = i.FirstOrDefault() })
      .Select(_ =&gt; new MainGridViewModel
      {
          INVOICE_DATE = _.d.INVOICE_DATE,
          EndCustomer = _.generic == null ? _.d.CUSTOMER_NAME : _.generic.EndCustomer ?? _.d.CUSTOMER_NAME,
          LINE_ORDERTYPE = _.i.OrderType
      })
      .ToList();
  </code></pre>
  
  <p>However I am having a syntax error that is written below;</p>
  
  <blockquote>
    <p>Error CS0411  The type arguments for method 'Enumerable.GroupJoin(IEnumerable, IEnumerable, Func, Func, Func, TResult>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.</p>
  </blockquote>