-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
File a bug
It's actually the same complaint as in #33683.
After the recent changes in EF Core 8, the default value for a boolean column in DB became "useless". I mean, It allows the EF Core to decide whether to send the value to the DB, but you can't skip setting the C# property and rely on the default value being set by the DB if it's different from the CLR default value.
I was able to work it around by adding = true; in the EntityType.t4 when the ClrType is bool and default value is true:
+ var needsBoolInitializer = property.ClrType == typeof(bool) && property.GetDefaultValue() is true;
#>
- public <#= code.Reference(property.ClrType) #><#= needsNullable ? "?" : "" #> <#= property.Name #> { get; set; }<#= needsInitializer ? " = null!;" : "" #>
+ public <#= code.Reference(property.ClrType) #><#= needsNullable ? "?" : "" #> <#= property.Name #> { get; set; }<#= needsInitializer ? " = null!;" : needsBoolInitializer ? " = true;" : "" #>
<#I think without these changes, the new behavior is harmful, and the true assignment should be built into the t4 template.
Include provider and version information
EF Core version: 8.0.7
Database provider: Pomelo.EntityFrameworkCore.MySql
Target framework: .NET 8
Operating system: Win10
IDE: Visual Studio 2022 17.10.4