title: LINQ LEFT JOIN on Nullable<int>
body: <p>I have two tables below:</p>
  
  <pre><code>Project(
      ProjectID       INT,
      Name            VARCHAR(200),
      AssignedUserID  INT NULL
  )
  User(
      UserID      INT,
      LastName    VARCHAR(50),
      FirstName   VARCHAR(50)
  )
  </code></pre>
  
  <p>I'm using Entity Framework Database-First approach. So in my Model:</p>
  
  <pre><code>Class Project{
      public int ProjectID;
      public string Name;
      public Nullable&lt;int&gt; AssignedUserID;
  }
  
  Class User{
      public int UserID;
      public string LastName;
      public string FirstName;
  }
  </code></pre>
  
  <p>I want to query all <code>PROJECT</code> and its assigned user:</p>
  
  <pre><code>SELECT
      p.ProjectID,
      p.Name,
      u.LastName,
      u.FirstName
  FROM Project p
  LEFT JOIN Users u ON u.UserID = p.AssignedUserID
  </code></pre>
  
  <p>Translating to Linq:</p>
  
  <pre><code>var projectDetails =
      from p in context.Project
      join u in context.User
          on p.AssignedUserID equals u.UserID into lj
      from x in lj.DefaultIfEmpty()
          select new {
              ProjectID = p.ProjectID,
              ProjectName = p.Name,
              UserLastName = u.LastName,
              UserFirstName = u.FirstName
          }
  </code></pre>
  
  <p>However, I'm getting an error:</p>
  
  <blockquote>
    <p>The type of one of the expressions in the join clause is incorrect. 
    Type inference failed in the call to 'Join'.</p>
  </blockquote>
  
  <p>I've tried both solutions on <strong><a href="https://stackoverflow.com/questions/12411172/int-and-int-comparison-when-left-outer-join-in-linq-issue">int? and int comparison when LEFT OUTER JOIN in Linq issue</a></strong>, but still it's giving me these errors:</p>
  
  <p>Using the solution: <code>(int)(p.AssignedUserID ?? default(int))</code></p>
  
  <blockquote>
    <p>LINQ to Entities does not recognize the method 'Int32 ToInt32(Int32)'
    method, and this method cannot be translated into a store expression.</p>
  </blockquote>
  
  <p>Using the solution <code>GetValueOrDefault()</code>:</p>
  
  <blockquote>
    <p>LINQ to Entities does not recognize the method 'Int32
    GetValueOrDefault(Int32)' method, and this method cannot be translated
    into a store expression.</p>
  </blockquote>
  
  <p>How do you do <code>LEFT JOIN</code> on <code>Nullable&lt;int&gt;</code> and <code>int</code>?</p>