title: Linq query with first or default join
body: <p>I have the following data model:</p>
  
  <pre><code>public class Course
  {
      public int CourseId { get; set; }
      public int StateId { get; set; }
  }
  
  public class CompletedCourse
  {
      public int CompletedCourseId { get; set; }
      public int UserId { get; set; }
      public Course Course { get; set; }
      public string LicenseNumber { get; set; }
  }
  
  public class License
  {
      public int LicenseId { get; set; }
      public int UserId { get; set; }
      public int StateId { get; set; }
      public string LicenseNumber { get; set; } 
  }
  </code></pre>
  
  <p>I'm trying to come up with an <code>IQueryable</code> for <code>CompletedCourses</code> and I would like to populate <code>CompletedCourse.LicenseNumber</code> with the <code>LicenseNumber</code> property of the <code>FirstOrDefault()</code> selection from my Licenses table where <code>UserId</code> and <code>StateId</code> match the completed course records.</p>
  
  <p>Here is my query, but I don't think this will handle duplicate licenses correctly:</p>
  
  <pre><code>var entries =
      (from course in context.CompletedCourses
           join license in context.Licenses on course.UserId equals license.UserId
           where license.StateId == course.Course.StateId
           select course)
      .Include(x =&gt; x.Agent)
      .Include(x =&gt; x.Course.State);
  </code></pre>
  
  <p>Is this something that can be done in a single query?  Thanks in advance.</p>