Disable conversion between VARCHAR and NVARCHAR when using Entity Framework over an existing SQL server database

.net entity-framework entity-framework-6 sql sql-server

Popular Answer

The typical data format forstring is columnsnvarchar(MAX) there is no need for you to change the data type in your columns before converting toNVARCHAR(MAX) . Ef has Specify default conventions. Knowing conventions is explained by the number here.

If you want a standard configuration for your models, you may follow these steps:

public class DataTypeConvention : Convention
{
    public DataTypeConvention()
    {
        Properties<string>().Configure(config => { config.HasColumnType("nvarchar(MAX)"); });
    }
}

based on your DbContext:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
   modelBuilder.Conventions.Add(new DataTypeConvention());
}
0
3/17/2018 8:46:30 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow