So, unlike SQL Server, in MySQL, the following property creates a column of type LONGTEXT
:
public string Name { get; set; }
I want to have an NVARCHAR(255)
column instead, so I tried the following:
//[DataType("NVARCHAR"), StringLength(255)] // creates a varchar(255) column.
[DataType("NVARCHAR"), MaxLength(255)] // creates a varchar(255) column.
public string Name { get; set; }
I also tried the following with Fluent API:
modelBuilder.Entity<MyEntity>()
.Property(p => p.Name)
.HasColumnType("NVARCHAR")
.HasMaxLength(255); // still creates a varchar(255) column.
..and:
modelBuilder.Entity<MyEntity>()
.Property(p => p.Name)
.HasColumnType("NVARCHAR(255)");
Which causes an InvalidOperationException
with the following message:
The store type 'NVARCHAR(255)' could not be found in the MySql provider manifest
Is there something I'm doing wrong? What is the correct way to create an nvarchar column using code-first?