Debug error message please. DbArithmeticExpression Arguments must be of a numeric generic type

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.

// 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 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."

+3
source share
2 answers

EF DateTime - DateTime.

+2

System.Data.Entity.DbFunctions.DiffHours :

fooobar.com/questions/29332/...

var expired = (from a in db.Baskets
               where DbFunctions.DiffHours(DateTime.Now, a.DateCreated) > 3
               select a);
0

All Articles