title: NullReferenceException when Selecting from Left Join
body: <p>I am trying to do 2 left joins. I have tested the query in SQL server and it works but I am unable to recreate the query in linq. </p>
  
  <p>The query:</p>
  
  <pre><code>select Master.InvoiceId,Consumer.ConsumerId,ConsumerCharge.ChargeId , Amount 
  from Master 
  
  left outer join  Consumer on 
  Master.InvoiceId=Consumer.InvoiceId 
  
  left outer join ConsumerCharge on 
  Consumer.ConsumerId = ConsumerCharge.ConsumerId and 
  Consumer.InvoiceId = ConsumerCharge.InvoiceId and 
  Master.InvoiceId = ConsumerCharge.InvoiceId
  
  order by InvoiceId
  </code></pre>
  
  <p>In LINQ:</p>
  
  <pre><code>var query = from m in IM.GetMaster()
  
              join co in CM.GetConsumers()
              on m.InvoiceId equals co.InvoiceId into temp2
              from co in temp2.DefaultIfEmpty()
  
              join ch in CCM.GetCharge()
              on new { co.InvoiceId, co.ConsumerId,  } equals new { ch.InvoiceId, ch.ConsumerId }   into temp
              from ch in temp.DefaultIfEmpty()
  
              orderby m.InvoiceId
              select new
              {
                  InvioceID = m.InvoiceId,
                  ConsumerID = co == null ? 0 : co.ConsumerId,
                  ChargeID = ch == null ? 0 : ch.ChargeId,
                  Amount = ch == null ? 0 : ch.Amount
              };
  </code></pre>
  
  <p>I am getting </p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <p>at  line <code>on new { co.InvoiceId, co.ConsumerId,  }</code>. If I remove <code>into temp2 from co in temp2.DefaultIfEmpty()</code>, it displays but invoice ids which does not have any consumer id is not displayed. How do I do a proper left join where 3 tables are involved?</p>