
AddDays in a LINQ Lambda Expression
January 25, 2012Using Entity Framework 4, we were trying to run a lambda expression that added an integer field from one table to a DateTime field in another related table.
.FindMany<Object1>(object1=> object1.DateCompleted.AddDays(object1.object2.NumberOfDays) <= System.DateTime.Now)
Got this error message:
LINQ entities does not recognize the method System.DateTime.AddDays Cannot be translated into a stored expression
What we had to do was use the System.Data.Objects.EntityFunctions.AddDays function instead. See Entity Functions - Add Days
.FindMany<Object1>(object1=> System.Data.Objects.EntityFunctions.AddDays(object1.DateCompleted, object1.objecto2.NumberOfDays) <= System.DateTime.Now)
Advertisement