Entity Framework Set StringLength VarChar Data Annotations

I have this setting in my model:

[StringLength(250)] public string Comment { get; set; } 

to set the maximum length to 250 in the database.

However, it is set as nvarchar (250) when the database person was expecting varchar (250).

Can someone please tell me how to set it as varchar from model, not nvarchar?

+29
entity-framework
Sep 08 2018-11-11T00:
source share
1 answer

Use ColumnAttribute to specify the data type.

 [Column(TypeName = "VARCHAR")] [StringLength(250)] public string Comment { get; set; } 

Or use the free API

 modelBuilder.Entity<MyEntity>() .Property(e => e.Comment).HasColumnType("VARCHAR").HasMaxLength(250); 
+58
Sep 08 2018-11-11T00:
source share



All Articles