Repository navigation
Translate the TimeSpan Total* members on SQL Server - #39487
Merged
AndriySvyryd merged 1 commit intoNov 4, 2026
Merged
Conversation
- TotalDays, TotalHours, TotalMinutes, TotalSeconds, TotalMilliseconds, TotalMicroseconds and TotalNanoseconds over a time value - The ticks are computed exactly from DATEPART and divided once, as in .NET, so the results are the same doubles Fixes dotnet#19632
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Exact .NET double-result coverage is incomplete for the other TimeSpan Total* translations, leaving potential last-bit mismatches undetected.
1 open issue
What changed in this PR
This pull request adds SQL Server translation support for all TimeSpan.Total* members while preserving .NET-compatible double results.
Changes:
- Reconstructs
TimeSpanticks from SQL ServerDATEPARTvalues and translatesTotalDays,TotalHours,TotalMinutes,TotalSeconds,TotalMilliseconds,TotalMicroseconds, andTotalNanoseconds. - Adds shared translation tests, SQL Server baselines, and projected
TotalHoursprecision coverage. - Confirms these members remain unsupported on SQLite and Cosmos.
- Nit (3 votes): Add exact scalar-projection coverage for the remaining members, particularly
TotalNanosecondsand the distinct divisor paths.
This pull request is ready to be approved.
| File | Summary |
|---|---|
test/EFCore.SqlServer.FunctionalTests/Query/Translations/Temporal/TimeSpanTranslationsSqlServerTest.cs |
Adds SQL baselines and projected-value validation for SQL Server translations. |
test/EFCore.Sqlite.FunctionalTests/Query/Translations/Temporal/TimeSpanTranslationsSqliteTest.cs |
Confirms the new members remain unsupported on SQLite. |
test/EFCore.Specification.Tests/Query/Translations/Temporal/TimeSpanTranslationsTestBase.cs |
Adds shared predicate tests for each Total* member. |
test/EFCore.Cosmos.FunctionalTests/Query/Translations/Temporal/TimeSpanTranslationsCosmosTest.cs |
Confirms the new members remain unsupported on Cosmos. |
src/EFCore.SqlServer/Query/Internal/Translators/SqlServerTimeSpanMemberTranslator.cs |
Implements tick-based SQL Server translation for all TimeSpan.Total* members. |
Review effort: Lite
AndriySvyryd
approved these changes
Nov 4, 2026
AndriySvyryd
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #19632
Hours,Minutes,Secondsand the other component members are already translated withDATEPART; theTotal*members were not, as noted in #19632 (comment).A SQL Server
timevalue is below 24 hours, so its number of ticks is computed exactly fromDATEPART, as abigint:Each
Total*member then divides it once, asTimeSpandoes (TotalNanosecondsmultiplies by 100), so the result is the samedoubleas in .NET. Adding up the parts separately (hour + minute / 60.0 + ...) gives a different last bit for some values: for 02:00:15.4562004,TotalHourswould be 2.0042933890000003 instead of 2.0042933889999999.TimeSpanTranslationsTestBasegets one test per member, with thresholds that depend on the fraction of a second. SQLite and Cosmos assert that the translation fails, as for the other members.TotalHours_in_projection(SQL Server) compares the projected values with .NET. With the parts added up separately it fails on the two values with a fraction of a second.Outside the tests, on SQL Server 2022 the seven members give the same bits as .NET for 0, 1 tick, 01:02:03, 03:04:05.6789124, 01:00:15.456, 02:00:15.4562004, 12:30 and 23:59:59.9999999.
On current
main, on Linux with SQL Server 2022:TimeSpanTranslationsSqlServerTest15/15, the SQL ServerQuery.Translationstests 431 passed (3 skipped),TimeSpanTranslationsSqliteTest14/14,TimeSpanTranslationsInMemoryTest13/13. The Cosmos tests were not run locally.I've read the guidelines for contributing and seen the walkthrough
I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
The code builds and tests pass locally (also verified by our automated build checks)
Commit messages follow this format: