2014-04-28 41 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!乾杯。