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?

1 Answer 1

1

Found a way - this works:

DateTime offsetHour = DateTime.Now.Add(new TimeSpan(-1, 0, 0));
backupEvents = backupEvents.Where(e => e.Timestamp >= offsetHour);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.