Hi @PostAlmostAnything ,
The only thing I added to the ApplicationUser class related to the IsApproved column is one line of code in ApplicationUser.cs which is as follows:
public bool IsApproved { get; set; }
By using the above code, the 'bool' property 'IsApproved' on entity type 'ApplicationUser' is configured with a database-generated default. This default will always be used for inserts when the property has the value 'false', since this is the CLR default for the 'bool' type. So, when insert the new entity, the default value is false
.
To set the default value when using EF Core, you can configure a default value on a property:
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<ApplicationUser>()
.Property(b => b.IsApproved)
.HasDefaultValue(true);
}
Then, use the Add-Migration
and Update-Database
command to enable migration and update the database.
After that, you can check the data table designer via the SQL Server Object Explorer, like this:
Then, after inserting new user, the default value will be True
:
[Note] The existing record's IsApproved
value will not change it. You need to change it by yourself. You can change them via the SQL Server Object Explorer and the AspNetUsers's data view or create a SQL query, refer the follow screenshot:
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion