title: Filter by nullable datetime field using Linq
body: <p>I'm trying to filter all rows in an SQL table that have a specific date. It works if the column is not nullable, but fails if it is.</p>
  
  <p>This works for not nullable datetime fields:</p>
  
  <pre><code>ent.MyTable.Where(e =&gt; e.MyDate.Day == 12);
  </code></pre>
  
  <p>Obviously this works not for nullable datetime fields. After doing some search on the Internet, I found many "solutions" to this problem that look like to following:</p>
  
  <pre><code>ent.MyTable.Where(e =&gt; e.MyDate != null &amp;&amp; e.MyDate.Day == 12);
  </code></pre>
  
  <p>Unfortunately this does not work for me either. And it is understandable why if I consider this error message:</p>
  
  <blockquote>
    <p>'System.Nullable' does not contain a definition for 'Day' and no extension method 'Day' accepting a first argument of type 'System.Nullable' could be found (are you missing a using directive or an assembly reference?)</p>
  </blockquote>
  
  <p>I want to avoid fetching <em>all</em> SQL rows and then filter in .NET since I am only interested in a very small number of rows. Is there any other way that I don't see at the moment?</p>