Mysql
 sql >> Database >  >> RDS >> Mysql

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

Con l'API fluente puoi usare 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();

Con le annotazioni, puoi dettare il tipo:

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