Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I perform date-part comparison in EF

i heard people saying date time comparison do not work just due to time part because datetime has time part.

in sql i always compare datetime like this way and it works fine

select * from employee
where convert(varchar,dob,112) > '20111201' // this yyyymmdd format.

how could i simulate this in a LINQ query?

like image 828
Thomas Avatar asked Sep 13 '12 18:09

Thomas


1 Answers

If you're using .NET 4 or above, just use the EntityFunctions.TruncateTime helper method. This will translate this type of datetime-to-date conversion to SQL for you.

from e in EfEmployeeContext
where EntityFunctions.TruncateTime(e.DOB) > new DateTime(2011,12,01);
like image 112
mclark1129 Avatar answered Sep 21 '22 16:09

mclark1129