How to use DateTime.AddDays(x) in Entity Framework

c# datetime entity-framework linq-to-entities

Question

I have this code:

from pr in e.ProgramSetup.Include("Program").Include("Program.Client")
        where pr.DateBegin < DateTime.Now
        && pr.DateEnd > DateTime.Now.AddDays(pr.DateEndOffset) 
select pr).ToList();

It does not work, because AddDays() is not possible to use for generating sql.

So is there some another way? Now i select everything and filter it finaly by foreach, but it is not good way in my opinion.

Problem is that pr.DateEndOffset is also only in db, it is not constant...

1
11
8/25/2014 8:36:12 PM

Popular Answer

using System.Data.Entity;
...
DbFunctions.AddDays(dateFromDataStore, numDaysToAdd);
11
1/11/2018 4:06:40 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow