Trying to run this query in my code:
var rslt = ent.AppointmentDiaries.Where(s => s.DateTimeScheduled >=
fromDate && EntityFunctions.AddMinutes(
s.DateTimeScheduled, s.AppointmentLength) <= toDate);
It keeps breaking up with:
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.
using entityframework 6.1.0 ...
I know about canonical gunctions, so I would expect EntityFunctions.AddMinutes to work with codefirst queries...
Any idea what I am doing wrong?
In Entity Framework 6 EntityFunctions
has been replaced by DbFunctions
. The old class is now marked as obsolete and will disappear in the future.
I must admit that it's not directly obvious when you google for release notes. There is however a blog describing how to upgrade to EF6 where this change is mentioned.
Yes it's just like @Gert said. Here is the code for it:
var rslt = ent.tbl_Appoiment_Diary.Where(s => s.DateTimeScheduled >= fromDate && DbFunctions.AddMinutes(s.DateTimeScheduled, s.AppointmentLenght) <= toDate);
Hope this helps. Thx again for the info @Gert! Cheers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With