尝试在我的代码中运行此查询:
var rslt = ent.AppointmentDiaries.Where(s => s.DateTimeScheduled >=
fromDate && EntityFunctions.AddMinutes(
s.DateTimeScheduled, s.AppointmentLength) <= toDate);
它一直与:
分手An exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
Additional information: LINQ to Entities does not recognize the method 'System.Nullable`1[System.DateTime] AddMinutes(System.Nullable`1[System.DateTime], System.Nullable`1[System.Int32])' method, and this method cannot be translated into a store expression.
使用entityframework 6.1.0 ...
我知道规范的连接,所以我希望EntityFunctions.AddMinutes能够处理codefirst查询......
知道我做错了吗?
答案 0 :(得分:6)
在实体框架6中,EntityFunctions
已被DbFunctions
取代。旧班级现已标记为过时,将来会消失。
我必须承认,当谷歌发布发行说明时,这并不是直接明显的。然而,有一个博客描述如何 upgrade to EF6提到了这种变化。
答案 1 :(得分:1)
是的,就像@Gert说的那样。这是代码:
var rslt = ent.tbl_Appoiment_Diary.Where(s => s.DateTimeScheduled >= fromDate && DbFunctions.AddMinutes(s.DateTimeScheduled, s.AppointmentLenght) <= toDate);
希望这会有所帮助。感谢@Gert!干杯。