Configure entity framework to use char instead of varchar

893 Views Asked by At

How can I configure an entity framework model to generate a table having columns of type CHAR(X) instead of VARCHAR(X) or NVARCHAR(X)?

1

There are 1 best solutions below

1
On BEST ANSWER

To use CHAR/NCHAR instead of VARCHAR/NVARCHAR

Use the IsFixedLength method in addition of HasMaxLength.

  builder.Property(x => x.MyField).HasMaxLength(10).IsFixedLength();

To use CHAR/VARCHAR instead of NCHAR/NVARCHAR

You need to call IsUnicode(false)

  builder.Property(x => x.MyField).IsUnicode(false);