dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.75k stars 3.18k forks source link

Introduce EF.Functions.DateDiffBig* overloads returning long #32278

Open moander opened 11 months ago

moander commented 11 months ago

What problem are you trying to solve?

Microsoft.Data.SqlClient.SqlException (0x80131904): The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.
      db.Bars.Where(x =>
          EF.Functions.DateDiffMinute(x.PeriodStart, x.PeriodEnd) > validForMinutes
      )

I can't use a less precise datepart so the solution is to use DATEDIFF_BIG.

      db.Bars.Where(x =>
          EF.Functions.DateDiffMinuteLong(x.PeriodStart, x.PeriodEnd) > validForMinutes
      )

Am I missing something?

roji commented 7 months ago

We could introduce DateDiffBig* overloads for this case. Note conversation in https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/1875#issuecomment-1987951733.