在开发环境中,以下 SQL 语句有效,但不适用于任何其他环境:
System.NotSupportedException:LINQ to Entities 无法识别“System.DateTime AddDays(Double)”方法,并且此方法无法转换为存储表达式。
相关代码:
bool hasSomethinglast14days = (from a in db.someTable
where a.SomeIntColumn == someIntVariable
&& a.CreateDate >= DateTime.UtcNow.AddDays(-14)
select a.someColumn).Any();
Run Code Online (Sandbox Code Playgroud)