将Entity Framework中的DateTime与Sql Server Compact数据库进行比较

时间:2010-07-04 13:35:41

标签: entity-framework sql-server-ce entity-sql

为什么这段代码抛出System.NotSupportedException告诉The specified method 'int? DateDiff(string, DateTime?, DateTime?)' on the type 'System.Data.Objects.SqlClient.SqlFunctions' cannot be translated into a LINQ to Entities store expression,虽然DateDiff有EdmFunction属性?

context.Users.Where(f => System.Data.Objects.SqlClient.SqlFunctions.DateDiff("second", f.LastLogOn, somedatetime) < 0)

1 个答案:

答案 0 :(得分:2)

以下是Entity SQL查询提供程序link支持的规范日期和时间函数的完整枚举。

尝试这样的事情

context.Users.Where(f=>EntityFunctions.DiffSeconds(f.LastLogOn, somedatetime)<0);