【发布时间】:2017-09-20 13:38:58
【问题描述】:
我正在尝试运行以下命令:
backupEvents = backupEvents.Where(e => e.Timestamp >= DateTime.Now - new TimeSpan(0, 1, 0, 0));
但这给了我一个错误提示
“DbArithmeticExpression 参数必须具有数字通用类型”。
搜索 StackOverflow,我发现 Arithmetic with DateTime is not supported in Entity Framework。
所以我尝试了:
backupEvents = backupEvents.Where(o => DbFunctions.DiffHours(o.Timestamp, DateTime.Now) <= 1);
但我也不能使用提供的 DbFunctions 作为解决方案,因为我使用的是 SQLite,但它没有它们,我收到一条错误消息:“没有这样的功能:DiffHours”
那么 - 有没有办法在 SQLite 中使用实体来比较日期?
【问题讨论】:
标签: c# linq sqlite datetime entity-framework-6