I am trying to delete all items which are older than 3 hours in a table, but get the following error...
DbArithmeticExpression arguments must have a numeric common type.
// Method to clean items in baskets table which are over 3 hours old.
public void CleanBasket()
{
var expired = (from a in db.Baskets
where (DateTime.Now - a.DateCreated).TotalHours > 3 select a);
foreach (Basket basket in expired) db.DeleteObject(expired);
db.SaveChanges();
}
I have never seen this error before, can anybody help me to debug please?
FYI, I have also tried... var expired = (from a in db.Baskets where (DateTime.Now.Subtract(a.DateCreated).Hours > 3) select a);
but I get the error message "LINQ to Entities does not recognize the method 'System.TimeSpan Subtract(System.DateTime)' method, and this method cannot be translated into a store expression."