-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect translation of date substraction. #10656
Comments
Hello @SSkovboiSS, |
Thank you @ralmsdeveloper, I have already found a workaround. Nevertheless this is a bug and has to be fixed, that's why I created this issue. |
All Right, but if you use TimeStamp, we'll be limited to Day, Hour, Minutes and Seconds. So it was implemented in EF.Functions, I do not believe the team wants to do this, for version 2.0.1, since it is close to launching 2.1 with this solution. |
@ralmsdeveloper the problem here is not about client or server evaluating, this query does not work at all, because it is getting translated into totally wrong SQL. And I am also ok with fix in 2.1. |
Exactly because there is no implementation for this: |
Alright, but why current implementation tries to perform this subtraction on database? Shouldn't it just client eval instead? |
This may already be fixed in the 2.1 code. @SSkovboiSS Can you test with the nightly builds, as listed on the repo homepage: https://github.com/aspnet/EntityFrameworkCore Assigning to @smitpatel, who will close if this is already fixed. |
@ajcvickers sure, I will test it tomorrow and give a feedback here. |
Just tested 2.1.0-preview1-28042 and it still fails. Query log;
|
@ajcvickers, Implemented in this commit Hugs! |
As per exception above & documentation of T-SQL (https://docs.microsoft.com/en-us/sql/t-sql/language-elements/subtract-transact-sql), - is not supported on datetime related types. SQLite just take initial numeric part and do subtraction which is totally incorrect result. PostGreSql actually translates subtraction and return timespan correctly. cc:@roji Removing milestone as there is no obvious fix for this. As a work-around, you can use DateDiff function on SqlServer to translate dates correctly or project out dates on client and do client side subtraction. |
@smitpatel to bring together all the various parts of the "datediff" work to a design meeting so we can discuss. This includes:
|
@ajcvickers @smitpatel just a suggestion, but if SQL Server does have a function that does date subtraction and returns a timespan, maybe you should have the C# subtraction operator translated to that function, rather than exposing a special |
@roji - The issue is, there is no function which returns timespan. DateDiff function on sql server allows extract parts of timespan. Therefore we added DateDiff functions on EF.Functions (also the fact linq2sql had them). SqlServer has direct translation for them but for other providers there is no direct translation. Rather it makes it cumbersome trying to mimic client side behavior. |
@smitpatel ah I see - makes sense... In that case it seems right to have the DateDiff function as SQL Server-specific, I think. |
Another idea would be to recognize patterns like I wonder also if we could establish a conversion between an int containing seconds or microseconds and a |
@divega It should also be remembered that we do not have TotalYears and TotalMonths. So there would be a need to create an extension method, which I believe to be what you do not intend to do! |
@ralmsdeveloper agreed that there are things that would be missing with that approach. That is what I meant when I said "not all of them will work". That may be a reason the |
Design meeting notes
|
sql-ce fyi? |
Gets translated into:
Which in turn throws:
This query should either be translated into DateDiff if possible or perform subtraction on client but definitely not throw.
Further technical details
EF Core version: 2.0.1
Database Provider: Microsoft.EntityFrameworkCore.SQLServer
Operating system: Windows 10 1703
IDE: Visual Studio 2017
The text was updated successfully, but these errors were encountered: