Comparing DateTime in Entity Framework with an Sql Server Compact database

风格不统一 提交于 2019-12-11 16:05:28

问题


Why this code throws a System.NotSupportedException telling that 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, though DateDiff has EdmFunction attribute?

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

回答1:


Here is a complete enumeration of canonical Date and Time functions supported by Entity SQL query provider link.

Try something like this

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


来源:https://stackoverflow.com/questions/3174831/comparing-datetime-in-entity-framework-with-an-sql-server-compact-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!