title: The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type
body: <p>Running this code.  Works fine on local dev server, but not on live server.</p>
  
  <pre><code>try
  {
      var qq =
      db.tblConstructReleaseDownloads
      .Where(c =&gt; c.UserID.HasValue &amp;&amp; c.UserID.Value == userID)
      .OrderBy(c =&gt; c.DateStarted)
      .ThenBy(c =&gt; c.ReleaseID);
  
      var query = db.GetCommand(qq).CommandText;
      HttpContext.Current.Response.Write(query + "&lt;br&gt;&lt;br&gt;");
  
      foreach (var d in qq)
      {
          HttpContext.Current.Response.Write("ID:" + d.ID + "&lt;br&gt;");
      }
  </code></pre>
  
  <p>This throws the error:</p>
  
  <pre><code>The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.
  </code></pre>
  
  <p>The command text it prints out is:</p>
  
  <pre><code>SELECT     ID, ReleaseID, IP, DateCompleted, BytesServed, UserID, DateStarted, BytesPerSecond, TrackerVisitID
  FROM         tblConstructReleaseDownloads AS t0
  WHERE     (UserID IS NOT NULL) AND (UserID = @p0)
  ORDER BY DateStarted, ReleaseID
  </code></pre>
  
  <p>I run this query on the live database and it works fine, no errors.</p>
  
  <p>Anyone got any ideas what is causing this?</p>