Repository navigation
Translate TimeOnly.Hour/Minute/Second on SQLite - #38341
Conversation
Add SqliteTimeOnlyMemberTranslator mapping Hour, Minute, and Second to
strftime('%H'/'%M'/'%S'), mirroring SqliteDateOnlyMemberTranslator. TimeOnly
is stored as TEXT, so these read cleanly with no precision loss.
Sub-second members (Millisecond/Microsecond/Nanosecond), AddHours/AddMinutes,
and the TimeSpan-dependent members (Add/Subtract/FromTimeSpan, see dotnet#18844) are
left as follow-ups.
Part of dotnet#25103
There was a problem hiding this comment.
Pull request overview
Adds SQLite query translation support for TimeOnly.Hour, TimeOnly.Minute, and TimeOnly.Second by mapping them to strftime() and casting to integer, enabling previously-failing base translation tests to run successfully.
Changes:
- Added a new SQLite member translator for
TimeOnlyto translateHour/Minute/Secondviastrftime('%H'/'%M'/'%S', ...). - Registered the new translator in
SqliteMemberTranslatorProvider. - Updated SQLite functional tests to execute the base tests and assert the generated SQL.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/EFCore.Sqlite.FunctionalTests/Query/Translations/Temporal/TimeOnlyTranslationsSqliteTest.cs | Switches Hour/Minute/Second tests from “translation failed” to asserting the expected strftime-based SQL. |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteTimeOnlyMemberTranslator.cs | Introduces TimeOnly member translation for Hour/Minute/Second using Strftime + Convert (CAST). |
| src/EFCore.Sqlite.Core/Query/Internal/SqliteMemberTranslatorProvider.cs | Registers the new SqliteTimeOnlyMemberTranslator so the translations are applied. |
|
@Aykuttonpc Can you please check #38341 (comment). |
@dotnet-policy-service agree |
Adds SQLite translation for
TimeOnly.Hour,TimeOnly.Minute, andTimeOnly.Second, which previously threw "could not be translated".Since
TimeOnlyis stored as TEXT ("HH:MM:SS[.fffffff]"), these map cleanly tostrftime, mirroring the existingSqliteDateOnlyMemberTranslator:This enables the corresponding base tests (
Hour,Minute,Second) inTimeOnlyTranslationsSqliteTest.I kept the PR focused on the three integer members that translate without precision concerns. The remaining pieces split naturally into follow-ups:
Millisecond/Microsecond/Nanosecond) — needstrftime('%f')sub-second parsingAddHours/AddMinutes— time modifiers with 24h wrap-aroundAdd(TimeSpan)/Subtract/FromTimeSpan— depend on TimeSpan support (SQLite: Translate TimeSpan members #18844)Part of #25103