'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported
Solution 1:
If you are using EF 6.0+, you can use DbFunctions.TruncateTime(DateTime?)
:
var query =
from t in context.Logs
where t.Title == title
&& DbFunctions.TruncateTime(t.Timestamp) == LogDate.Date
select t;
Note: For earlier version of EF where
DbFunctions
isn't available,EntityFunctions.TruncateTime(DateTime?)
can be used instead.
Solution 2:
Not the greatest solution, but it works. For a variety of reasons, I have to use .net 3.5 at this point and modifying the database would be difficult. Anyways, here is a solution that works:
var query = from t in context.Logs
where t.Title == title
&& t.Timestamp.Day == LogDate.Day
&& t.Timestamp.Month == LogDate.Month
&& t.Timestamp.Year == LogDate.Year
select t;
Not the most elegant solution, but it is effective.
Solution 3:
EntityFunctions.TruncateTime(t.Timestamp) is obsolete from EF6.
Use below
DbFunctions.TruncateTime(t.Timestamp)
Solution 4:
Always use EntityFunctions.TruncateTime() for both x.DateTimeStart and LogDate. such as :
var query = from t in context.Logs
where t.Title == title
&& EntityFunctions.TruncateTime(t.Timestamp) == EntityFunctions.TruncateTime(LogDate)
select t;