2

I'm trying to run the following:

backupEvents = backupEvents.Where(e => e.Timestamp >= DateTime.Now - new TimeSpan(0, 1, 0, 0));

But this gives me an error saying

"DbArithmeticExpression arguments must have a numeric common type".

Searching StackOverflow, I find that Arithmetic with DateTime is not supported in Entity Framework.

So I tried:

backupEvents = backupEvents.Where(o => DbFunctions.DiffHours(o.Timestamp, DateTime.Now) <= 1);

But I also can't use the DbFunctions offered as a solution, because I'm using SQLite, and it doesn't have them, and I get an error saying: "no such function: DiffHours"

So - is there a way to compare dates in SQLite, using entity?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Maverick Meerkat
  • 5,737
  • 3
  • 47
  • 66

1 Answers1

1

Found a way - this works:

DateTime offsetHour = DateTime.Now.Add(new TimeSpan(-1, 0, 0));
backupEvents = backupEvents.Where(e => e.Timestamp >= offsetHour);
Maverick Meerkat
  • 5,737
  • 3
  • 47
  • 66