title: Linq left outer join not working using DefaultIfEmpty
body: <p>Using the technique found on the MSDN article <a href="http://msdn.microsoft.com/en-us/library/vstudio/bb397895.aspx" rel="nofollow noreferrer">&quot;How to: Perform Left Outer Joins (C# Programming Guide)&quot;</a>, I attempted to create a left outer join in my Linq code. The article mentions using the <code>DefaultIfEmpty</code> method in order to create a left outer join from a group join. Basically, it instructs the program to include the results of the left (first) collection even if there are no results in the right collection.</p>
  <p>The way this program executes, however, it does so as if the outer join has not been specified.</p>
  <p>In our database, <code>AgentProductTraining</code> is a collection of courses our agents have taken. Normally you cannot enter a <code>Course</code> onto it's appropriate table without entering a corresponding value into the <code>CourseMaterials</code> table. However, occasionally this may happen, so we want to make sure we return results even when a <code>Course</code> is listed in <code>AgentProductTraining</code> without any corresponding information in <code>CourseMaterials</code>.</p>
  <pre><code>var training = from a in db.AgentProductTraining
      join m in db.CourseMaterials on a.CourseCode equals m.CourseCode into apm
      where
          a.SymNumber == id 
          from m in apm.DefaultIfEmpty()
          where m.EffectiveDate &lt;= a.DateTaken
          &amp;&amp; ((m.TerminationDate &gt; a.DateTaken) | (m.TerminationDate == null))
              select new
              {
                  a.AgentProdTrainId,
                  a.CourseCode,
                  a.Course.CourseDescription,
                  a.Course.Partner,
                  a.DateTaken,
                  a.DateExpired,
                  a.LastChangeOperator,
                  a.LastChangeDate,
                  a.ProductCode,
                  a.Product.ProductDescription,
                  m.MaterialId,
                  m.Description,
                  a.Method
              };
  </code></pre>