You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, when scaffolding a SQL Server database with `date` or `time` columns, EF would generate entity properties with types [`DateTime`](https://learn.microsoft.com/dotnet/api/system.datetime) and [`TimeSpan`](https://learn.microsoft.com/dotnet/api/system.timespan).
30
+
31
+
#### New behavior
32
+
33
+
Starting with EF Core 8.0, `date` and `time` are scaffolded as [`DateOnly`](https://learn.microsoft.com/dotnet/api/system.dateonly) and [`TimeOnly`](https://learn.microsoft.com/dotnet/api/system.timeonly).
34
+
35
+
#### Why
36
+
37
+
`DateOnly` and `TimeOnly` were introduced in .NET 6.0, and are a perfect match for mapping the database date and time types. `DateTime` notably contains a time component that goes unused and can cause confusion when mapping it to `date`, and `TimeSpan` represents a time interval - possibly including days - rather than a time of day at which an event occurs. Using the new types prevents bugs and confusion, and provides clarity of intent.
38
+
39
+
#### Mitigations
40
+
41
+
This change only affects users which regularly re-scaffold their database into an EF code model ("database-first" flow).
42
+
43
+
It is recommended to react to this change by modifying your code to use the newly scaffolded `DateOnly` and `TimeOnly` types. However, if that isn't possible, you can edit the scaffolding templates to revert to the previous mapping. To do this, set up the templates as described on [this page](xref:core/managing-schemas/scaffolding/templates). Then, edit the `EntityType.t4` file, find where the entity properties get generated (search for `property.ClrType`), and change the code to the following:
0 commit comments