How do I perform Date Comparison in EF query?
c#, datetime, datetime-comparison, linq, linq-to-entities
Solution
That should work. Are you sure that there isn't another part of the query that triggered the exception? I have several instances of queries of the form
var query = from e in db.MyTable
where e.AsOfDate <= DateTime.Now.Date
select e;
in my code.
Problem
Please help. I am trying to figure out how to use DATE or DATETIME for comparison in a linq query. Example: If I wanted all Employee names for those who started before today, I would do something like this in SQL: ``` SELECT EmployeeNameColumn FROM EmployeeTable WHERE StartDateColumn.Date <= GETDATE() //Today ``` But what about linq? ``` DateTime startDT = //Today var EmployeeName = from e in db.employee where e.StartDateColumn <= startDT ``` The above WHERE doesn't work: Exception Details: System.NotSupportedException: The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.