Entitiy Framework Core preview 2 - default value for boolean

We used .Net Core 1 and we migrated to Preview 2 (both with Entity). Before migration, we used the default for boolean

in Entity Framework as follows:

modelBuilder.Entity<Customer>()
  .ToTable("Customer")
  .Property(a => a.Active)
  .HasDefaultValue(true);

      

We didn't change anything after the migration, but now we get an error when an object tries to create this table. It looks like it is trying to create the default as a string like "True" and not as a bit like it used to.

Does anyone know what has changed?

ERROR in update database

The "bool" "Active" property for the "Client" entity type is configured by default for the database. This default will always be used if the property is false, as this is the CLR default for the bool type. Consider using nullable 'bool?' instead enter a default value only if the property value is "null".

Script generated:

CREATE TABLE `Customer` (
    `Id` int NOT NULL,
    `Active` bit NOT NULL DEFAULT 'True'
   )

      

+3


source to share





All Articles