Create varchar using Entity Framework Core 2 Code First
It is working now with [Column(TypeName = "varchar(50)")]
.
I think when I deleted the database tables and deleted the migration from the migrations table using SSMS, it was not actually deleting the tables so it appeared that they were getting created the same way as before with the nvarchar(MAX)
when I refreshed the tables folder in SSMS.
So [Column(TypeName = "varchar(50)")]
works fine.
Had the same issue but I'm using Fluent API for configuration. So, if you'd be willing to use Fluent to configure your model then:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<MyEntity>()
.Property(x => x.Name)
.HasMaxLength(50)
.IsUnicode(false);
}
As EF now knows you don't need Unicode it'll use VARCHAR
instead of NVCHAR
.
This combined with HasMaxLength
will result in your desired VARCHAR(50)
.