I am trying to delete all items that are older than 3 hours in a table, but get the following error ...
The arguments to DbArithmeticExpression must be of a numeric common type.
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 someone help me debug, please?
FYI, I 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) ", and this method cannot be translated into a storage expression."
Gravy source
share