I'm trying to do this:
Tickets.Where(t => (t.Date - myTicket.Date) < TimeSpan.FromSeconds(120));
I'm getting the "DbArithmeticExpression arguments must have a numeric common type" error. How can I do this, considering that I need the difference in a TimeSpan?
Thanks in advance.
You would want to use SqlFunctions.DateDiff
Tickets.Where(t =>
SqlFunctions.DateDiff("second", t.Date, myTicket.Date) < 120));
You can also use this;
var result = db.Tickets.Where(t =>
SqlMethods.DateDiffSecond(myTicket.Date , t.Date) < 120);
Arithmetic with DateTime is not supported in Entity Framework. You have to use one of the SqlFunctions. So, for your statement, something like:
Tickets.Where(t =>
SqlFunctions.DateDiff("second", t.Date, myTicket.Date) < 120));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With