Arithmetic with DateTime
is not supported in Entity Framework 6 and earlier. You have to use DbFunctions*. So, for the first part of your statement, something like:
var sleeps = context.Sleeps(o =>
DbFunctions.DiffHours(o.ClientDateTimeStamp, clientDateTime) < 24);
Note that the DiffHours
method accepts Nullable<DateTime>
.
Entity Framwork core (when used with Sql Server, maybe other db providers) supports the DateTime AddXxx
functions (like AddHours
). They’re translated into DATEADD
in SQL.
*EntityFunctions
prior to Entity Framework version 6.