I have a problem comparing dates in LINQ with entity expressions. I would like to check if DateTime == DateTime - whole day .
I wanted to do it like this:
return context.Events.Any(x => x.UserId == id && x.Date >= date && x.Date < date.AddDays(1) && x.Type == EventType.StartWork);
The problem is that the above query is incorrect in LINQ due to the AddDays () method.
I tried using DbFunctions as shown below:
return context.Events.Any(x => x.UserId == id && x.Date >= date && x.Date < DbFunctions.AddDays(date, 1) && x.Type == EventType.StartWork);
Also this one:
return context.Events.Any(x => x.UserId == id && DbFunctions.TruncateTime(date.Date) == date.Date && x.Type == EventType.StartWork);
None of these queries produce the expected results.
source share