title: Entity Framework not able to count the records for nullable types
body: <p>Hi I have a class which returns the System.Linq.Expression for my filter values.</p>
  
  <pre><code> var deleg = ExpressionBuilder.GetExpression&lt;T&gt;(SearchFilter).Compile();
   query = query.Where(deleg).AsQueryable();
  </code></pre>
  
  <p>On this query I am applying sorting and paging which results in expression as: </p>
  
  <pre><code>{System.Linq.Enumerable+WhereEnumerableIterator`1[Domain.Database.Edmx.MyViewTable].OrderBy(item =&gt; item.START_TIME).Skip(10).Take(10)}
  </code></pre>
  
  <p>Now when I apply <code>.TOList()</code> to this query :</p>
  
  <pre><code> var list = query.ToList();
  </code></pre>
  
  <p>It results in error :</p>
  
  <blockquote>
    <p>The cast to value type 'System.Int32' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.</p>
  </blockquote>
  
  <p>My Entity Generated  Looks Like this :</p>
  
  <pre><code>public partial class MyViewTable
  {
      public System.DateTime START_TIME { get; set; }
      public Nullable&lt;System.DateTime&gt; END_TIME { get; set; }
      public Nullable&lt;System.DateTime&gt; INTERVAL_START { get; set; }
      public Nullable&lt;System.DateTime&gt; INTERVAL_END { get; set; }
      public Nullable&lt;int&gt; FILE_Num { get; set; }
      public string PROGRAM_Num { get; set; }
      public string FILETYPE { get; set; }
      public string DIRECTION { get; set; }
  }
  </code></pre>
  
  <p>Please Help!</p>