Wednesday, October 26, 2011

LINQ to Entities does not recognize the method 'System.DateTime AddHours(Double)'

Problem:
LINQ to Entities does not recognize the method 'System.DateTime AddHours(Double)'

Old Code:
DateTime cutOffDateTime = DateTime.Now.AddHours(-updatedWithInNumberOfHours);


Solution:
DateTime cutOffDateTime = DateTime.Now.Subtract(new TimeSpan(0, updatedWithInNumberOfHours, 0, 0));

No comments:

Post a Comment