In Entity Framework 6.X It was possible to change the default database type by doing this:
modelBuilder.Properties<string>().Configure(c => c.HasColumnType("varchar"));
In EF Core how can i do that?
The method Properties() doesn´t exists.
In Entity Framework 6.X It was possible to change the default database type by doing this:
modelBuilder.Properties<string>().Configure(c => c.HasColumnType("varchar"));
In EF Core how can i do that?
The method Properties() doesn´t exists.
Since EF Core 6, based on github repository of entity framework (see here) :
previous versions of EF Core (before EF Core 6) require that the mapping for every property of a given type is configured explicitly when that mapping differs from the default. This includes "facets" like the maximum length of strings and decimal precision, as well as value conversion for the property type.
In the class that inherits from DbContext
override ConfigureConventions
protected override void ConfigureConventions(
ModelConfigurationBuilder configurationBuilder)
{
configurationBuilder
.Properties<string>()
.AreUnicode(false)
.HaveMaxLength(1024);
}
Thus all string properties can be configured to be ANSI (instead of Unicode) and have a maximum length of 1024, hence mapping string to nvarchar
changes to varchar
when migrations are applied to the database.