c# - Compare Just Date Part of 2 DateTime Variables in LINQ with EF -


problem: have search form allows users search record date falls between 2 dates (mm/dd/yyyy)

all of records , objects of type datetime need compare date parts not time part.

according msdn, date property supported in linq statement written not allow me append .date lambda part:

error:

the specified type member 'date' not supported in linq entities. initializers, entity members, , entity navigation properties supported. 

example:

x.datecreated.date 

i sure problem comes lot - how solve it?

i guess pad other date appending 23:59:59 = 86399 secs <= part

here statement. (db context object)

 model.contacts =                  db.prospects.where(x => x.datecreated >= df.date && x.datecreated <= dt.date)                     .orderbydescending(x => x.datecreated)                     .take(100)                     .tolist(); 

you should use truncatetime function:

entityfunctions.truncatetime(x.datecreated)  

Comments