2010-07-04 71 views
0

爲什麼這段代碼拋出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屬性?將Entity Framework中的DateTime與Sql Server Compact數據庫進行比較

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

回答

2

這裏是一個實體SQL查詢提供link支持規範的日期和時間功能的完整枚舉。

嘗試是這樣的

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

感謝的答案,但是這是不SQLCE SQL服務器,它不支持任何比較比則DateDiff等功能。 – Parsa 2010-07-07 06:48:28

+0

據我瞭解,這個函數會被翻譯成DateDiff。試試看:) – 2010-07-07 07:52:57

+0

對於實體框架版本6,考慮使用'DbFunctions.DiffSeconds' – Dherik 2015-05-11 17:42:47

相關問題