-
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
Add SqlServer translation for DateOnly.ToDateTime(timeOnly) #35194
base: main
Are you sure you want to change the base?
Conversation
The translation is done as expected but I have issue in the where comparison which compare date with datetime Error Message on test:
SQL sent to the database: SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline]
FROM [Missions] AS [m]
WHERE DATETIMEFROMPARTS(DATEPART(year, [m].[Date]), DATEPART(month, [m].[Date]), DATEPART(day, [m].[Date]), DATEPART(hour, [m].[Time]), DATEPART(minute, [m].[Time]), DATEPART(second, [m].[Time]), DATEPART(millisecond, [m].[Time])) = '1990-11-10T10:15:50.5000000' |
@dotnet-policy-service agree |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the translation should be to DATETIME2FROMPARTS (which returns SQL Server datetime2
), rather than DATETIMEFROMPARTS (which returns the discouraged datetime
.
We also need to refrain from doing the translation when either the DateOnly or the TimeOnly are a complex SQL expression (anything other than a column/constant/parameter), for performance reasons; see #35076 (comment).
src/EFCore.SqlServer/Query/Internal/Translators/SqlServerDateOnlyMethodTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Internal/Translators/SqlServerDateOnlyMethodTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Internal/Translators/SqlServerDateOnlyMethodTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Internal/Translators/SqlServerDateOnlyMethodTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Internal/Translators/SqlServerDateOnlyMethodTranslator.cs
Show resolved
Hide resolved
- use array literal - use DATETIME2FROMPARTS - use time 7 fractions instead of milisecond - add support for constant DateOnly Fixes dotnet#35194
Fixes #35076
I created the PR as draft
please guide where to look
DateOnly
as constant withTimeOnly
Property