title: LINQ to Entities generating incorrect SQL
body: <p>I am filtering an IQueryable to return all entities that have the field UserId (a nullable int) set to null. The query generates the incorrect SQL and thus fails -- the statement is
  as follows -</p>
  
  <pre><code>var filtered = certificates.Where(c =&gt; !c.UserId.HasValue).Select(c =&gt; c.SubjectName);
  </code></pre>
  
  <p>and the generated SQL is -- </p>
  
  <pre><code>SELECT 
  CAST(NULL AS varchar(1)) AS [C1], 
  CAST(NULL AS int) AS [C2], 
  CAST(NULL AS datetime2) AS [C3], 
  CAST(NULL AS datetime2) AS [C4], 
  CAST(NULL AS bit) AS [C5], 
  CAST(NULL AS datetime2) AS [C6], 
  CAST(NULL AS int) AS [C7]
  FROM  ( SELECT 1 AS X ) AS [SingleRowTable1]
  WHERE 1 = 0
  </code></pre>
  
  <p>Any idea WTF is going on? The idea is simple I just want to return all the rows where the field UserId is false. UserId is nullable and the table being queried has three rows that match the condition described, however the LINQ query returns 0.</p>
  
  <p>Thanks!</p>