title: How to left outer join for two unequal lists in linq
body: <p>What I mean by two unequal lists is:</p>
  
  <p>LIST 1:</p>
  
  <pre><code>LeaveType  Openning
  ---------  --------
  Casual        25
  Annual        30
  Medical       23
  </code></pre>
  
  <p>LIST 2:</p>
  
  <pre><code>LeaveType  Availed
  ---------  -------
  Casual       3
  Annual       5
  </code></pre>
  
  <p>Notice that the two lists above have unequal number of rows, I'm trying to combine the above two lists through an identical column i.e <code>LeaveType</code> by left joining the two lists to get the result as below:</p>
  
  <p>OUTPUT LIST:</p>
  
  <pre><code>LeaveType  Openning  Availed
  ---------  --------  -------
  Casual        25        3
  Annual        30        5
  Medical       23        0
  </code></pre>
  
  <p>What I've tried so far is the below linq query:</p>
  
  <pre><code>(from o in LIST1
    join a in LIST2
    on o.LeaveType equals a.Leave_Type
    into temp
    from a in temp.DefaultIfEmpty()
    select new
    {
       LeaveType = o.LeaveType,
       Openning = o.Openning,
       Availed = a.Availed == 0 ? 0 : a.Availed,         
    }).ToList();
  </code></pre>
  
  <p>The above query works fine for creating the first two rows of the output list but when it comes for about creating the third row, it throws <code>NullReferenceException</code>, even if I put the check as <code>a.Availed == 0 ? 0 : a.Availed</code> to return zero, the <code>a.Availed</code> is of type <code>decimal</code>, but still it throws the <code>NullReferenceException</code>, Why? and how to get rid of this? Thanks :)</p>
  
  <p><strong>Edit</strong></p>
  
  <p><code>NullReferenceException</code> just for evidence:</p>
  
  <p><a href="https://i.stack.imgur.com/oFkz5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oFkz5.png" alt="enter image description here"></a></p>