EF Core 8 HasDefaultValue for bool (bit in database) is not working

184 Views Asked by At

I am upgrading a web application from .NET Core 2.1 to .NET 8 and, besides problems with the Nullable setting, now I have a new problem: all the default settings for BIT column types (boolean in C# code) are not working anymore when adding new records.

The settings for these columns are the following (using Fluent API):

builder.Entity<Product>(db =>
{
    db.Property(ss => ss.IsActive).HasDefaultValue(true);
});

The field declaration in the class is the following:

[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
[Display(Name = "Status")]
public bool IsActive { get; set; }

The setting for DateTime columns works without problems.

Are there any changes regarding this setting that I missed? I searched for answers, but I didn't find anything relevant.

0

There are 0 best solutions below