title: How to add left outer join to grouped and summed LINQ query
body: <p>I have an Employees table:</p>
  
  <pre><code>EmployeeID  |  EmployeeName
  ---------------------------
  1           |  Jack
  2           |  Jill
  3           |  Roger
  </code></pre>
  
  <p>And an Occurrences table:</p>
  
  <pre><code>OccurrenceID  |  EmployeeID  |  Points
  --------------------------------------
  1             |  1           |  5
  2             |  2           |  3
  3             |  1           |  1
  </code></pre>
  
  <p>I have a working LINQ query that groups and sums the two table together:</p>
  
  <pre><code>groupedOccurrences = (from o in db.Occurrences.Include(o =&gt; o.Employee)
                        where o.OccurrenceDate &gt;= beginDate
                           &amp;&amp; o.OccurrenceDate &lt;= endDate
                        group o by o.Employee.EmployeeName into g
                        select new OccurrenceByQuarter
                        {
                            Name = g.Key,
                            Total = g.Sum(o =&gt; o.Points)
                         });
  </code></pre>
  
  <p>Which produces this output:</p>
  
  <pre><code> Jack 6
   Jill 3
  </code></pre>
  
  <p>But I want to also have employee Roger show up in the output with 0 points.  I've tried adding a join to the LINQ query like this:</p>
  
  <pre><code>groupedOccurrences = (from e in db.Employees
                        from o in db.Occurrences
                        join o in db.Occurrences on e.EmployeeID equals o.EmployeeID into j1
                        from j2 in j1.DefaultIfEmpty()
                        group j2 by e.EmployeeName into g
                        select new OccurrenceByQuarter
                        {
                            Name = g.Key,
                            Total = g.Sum(o =&gt; o.Points)
                        });
  </code></pre>
  
  <p>But I end up with the number of points being vastly inflated (as in 24 times what they're supposed to be).</p>
  
  <p>I've also tried to get the Total to return 0 if null by changing the declaration of Total to <code>public int? Total { get; set; }</code> in my OccurrencesByQuarter class but then when I try to change the LINQ query to include <code>Total = g.Sum(o =&gt; o.Points) ?? 0</code> I get an error that says "operator ?? cannot be applied to operands of type int and int".</p>
  
  <p>Any help would be much appreciated.</p>