-
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 more DateTimeOffset member translations #26781
Comments
Looks good - I personally think that using
There's Note that this translates the concept of the local .NET machine time zone to the SQL Server time zone - which I think is right and consistent with other translations we have (I've done the same for PostgreSQL). But it's probably a good idea to make this explicit in the translation docs. |
@roji I did come across that but unfortunately it (along with |
@stevendarby odd, I just tested this on my local SQL Server (2019) and I suspect the docs here are incorrect, and the intention is to say that the function is supported on regular SQL Server too, but always returns UTC on SQL Azure? |
Ah, I have 2017 installed locally and it doesn't work there. Just found a source saying it's a 2019+ feature. It also has the workaround for older versions. |
Great, makes sense (I wrote some feedback on the SQL Server docs that they should fix it). I think it's OK to translate for SQL Server 2019 here, especially since there's no real alternative (EF Core translations can't rely on the registry->variable trick). Users who really need this should be able to define a user function which does this trick though. |
Just had a quick play with SQL Server 2019, and oddly, while |
Yeah, seems like you're right @stevendarby. DateTimeOffset.LocalDateTime may not be translatable. I have my doubts about the usefulness of a time zone conversion that uses SQL Server's configured local time zone though. I'm not sure many users will miss this. |
Note from triage: yes for the first two. |
@stevendarby if you're interesting in working on this, we'd be happy to have a PR! |
@stevendarby note #26972 which adds support for AT TIME ZONE (though not sure this is needed for this issue per se). |
Hi @roji, just to check, is 2016+ ok then? I know there is now support for |
I think we should be OK with translating a .NET method in a way which doesn't work on old database versions. Especially when when that .NET method isn't currently translated at all (so nobody is being broken), and there doesn't seem to be any satisfactory translation which doesn't rely on a newer database version. So I don't think there's any particular blocker for adding new DateTimeOffset translations which rely on 2016+, and which we don't currently translate. |
Currently some DateTimeOffset members shared with DateTime are translated, e.g. https://github.com/dotnet/efcore/blob/c8c6c21cafb9d25b7d8f3be316fd806cb2132de5/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMemberTranslator.cs
Could add some more translations for instance members specific to DateTimeOffset. Some thoughts/suggestions for SQL Server:
DateTimeOffset.DateTime ->
CONVERT(datetime2, @dateTimeOffset)
-- Lop off the offset
DateTimeOffset.UtcDateTime ->
CONVERT(datetime2, SWITCHOFFSET(@dateTimeOffset, '+00:00'))
-- Adjust to 0 offset then lop off the offset
--
@dateTimeOffset AT TIME ZONE 'UTC'
is an alternative for the adjustment part, but is only supported in 2016+DateTimeOffset.LocalDateTime
-- Don't think this can be translated without
AT TIME ZONE
and a simple way to get the current timezone ID from SQL Server.The text was updated successfully, but these errors were encountered: