How do I configured fixed length columns in EF Core?

ef-code-first ef-fluent-api ef-migrations entity-framework entity-framework-core

Question

In the previous EF, I could do this:

  entityTypeBuilder
    .Property(b => b.Foo)
    .IsRequired()
    .HasMaxLength(10)
    .IsFixedLength();

That would generate a migration with something like

Foo = c.String(nullable: false, maxLength: 10, fixedLength: true)

However in EF Core there is no IsFixedLength().

Is there some other way of doing this?

1
9
11/24/2016 9:35:11 AM

Accepted Answer

Currently (EF Core 1.1.0) you can only specify column type directly: .HasColumnType("char(123)")

Please make sure your DB engine understand this value! It is passed "as is".

Also please note that you should write all required dimension/length/precision values here, because .HasMaxLength() value will be ignored.

10
11/24/2016 2:10:44 PM

Popular Answer

Actually, as for Version 2.1 this is implemented as:

entity.Property(e => e.Name).HasMaxLength(X).IsFixedLength();


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow