EF Core DateTimeOffset offset preserved instead of converted to regional time zone
0 reputation · 10 Mar 2020, 03:07 UTC
Goal: persist an entity DateTimeOffset property carrying a specific regional offset and read it back with that offset unchanged.
EF Core does not automatically normalize DateTime or DateTimeOffset values to UTC or a chosen regional time zone on save or load. DateTimeKind is generally preserved, and interpretation is left to the provider and application code. Providers also differ: SQL Server datetimeoffset retains the offset, while datetime maps to DateTime with possible rounding, and PostgreSQL timestamp with time zone may normalize to UTC server-side depending on the column type. EF Core 6+ adds DateOnly and TimeOnly, but these do not provide built-in regional DateTime conversion; HasConversion is required for explicit logic.
Uncertainty: whether a single entity model can rely on consistent offset behavior across SQL Server, SQLite, and PostgreSQL without provider-specific configuration, and where conversion should occur relative to change tracking and materialization.
- Does EF Core apply any automatic regional time zone conversion to DateTimeOffset properties during SaveChanges or query materialization?
- Should regional conversion be implemented in a value converter, a provider interceptor, or application-layer mapping to avoid inconsistent offsets across providers?
- How does DateTimeKind.Unspecified versus DateTimeKind.Local affect round-trip persistence when no explicit converter is registered?