2014-04-28 42 views
3

试图运行该查询在我的代码实体:规范功能在LINQ to不工作

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

...

我知道关于canonical gunctions,所以我希望EntityFunctions.AddMinutes与codefirst查询一起工作...

任何想法我做错了什么?

+0

'EntityFunctions'已成为'DbFunctions'。 –

+0

非常感谢。我们应该如何知道?为什么不删除旧的* *困惑*。感谢队友这工作得很好。你应该发布它作为答案,所以我可以给你一个赞许:) –

回答

5

在实体框架中6 EntityFunctions已被替换为DbFunctions。现在老班级已经过时了,将来会消失。

我必须承认,当谷歌发布笔记时,它不是直接显而易见的。然而,有一篇博客描述如何在提到这种变化的地方提供 upgrade to EF6

+0

它真的不明显 – Void

1

是的,就像@Gert说的。这里是它的代码:

var rslt = ent.tbl_Appoiment_Diary.Where(s => s.DateTimeScheduled >= fromDate && DbFunctions.AddMinutes(s.DateTimeScheduled, s.AppointmentLenght) <= toDate); 

希望这会有所帮助。 Thx再次为info @Gert!干杯。