Entity Framework Code First MaxLength and FixedLegth (char vs varchar) Entity Framework Code First MaxLength and FixedLegth (char vs varchar) mysql mysql

Entity Framework Code First MaxLength and FixedLegth (char vs varchar)


With the fluent api you can use IsFixedLength():

//Set StudentName column size to 50 and change datatype to nchar //IsFixedLength() change datatype from nvarchar to nchar  modelBuilder.Entity<Student>()                    .Property(p => p.StudentName)                    .HasMaxLength(50).IsFixedLength();

With annotations, you can dictate the type:

[Column(TypeName = "char")][StringLength(2)]public string MyCharField { get; set; }