title: Compare Just Date Part of 2 DateTime Variables in LINQ with EF
body: <p>Problem:
  I have a search form that allows users to search for something where the record date falls between 2 dates (mm/dd/yyyy)</p>
  
  <p>All of the records and objects are of type Datetime but all I need to compare is the date parts not the time part.</p>
  
  <p>According to MSDN, the Date property is supported in LINQ however this statement as written will not allow me to append .Date to the lambda part:</p>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
  </code></pre>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>x.DateCreated.Date
  </code></pre>
  
  <p>I am sure this problem comes up a lot - How do I solve it? </p>
  
  <p>I guess I could pad the other date by appending 23:59:59 = 86399 secs to the &lt;= part</p>
  
  <p>Here is the statement. (db is a context object)          </p>
  
  <pre><code> model.Contacts = 
                  db.Prospects.Where(x =&gt; x.DateCreated &gt;= df.Date &amp;&amp; x.DateCreated &lt;= dt.Date)
                      .OrderByDescending(x =&gt; x.DateCreated)
                      .Take(100)
                      .ToList();
  </code></pre>