Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure fixed length columns in EF Core?

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?

like image 436
grokky Avatar asked Nov 24 '16 09:11

grokky


People also ask

How do I add a column in EF core?

If you want to add a new column to the database table which was already created using add-migration and update-database, one needs to again run the command (add-migration) in nuget package manager console with a new migration name (add-migration "Name2") and then run the command (update-database).

What is convention in EF core?

The basic shape of the model is detected by using conventions. Conventions are sets of rules that are used to automatically configure a conceptual model based on class definitions when working with Code First. The conventions are defined in the System.


1 Answers

For anyone coming to this issue like I did earlier today if you are looking for the IsFixedLength() function it is an extension method on the RelationalPropertyBuilderExtensions class in the Microsoft.EntityFrameworkCore.Relational package

like image 126
Buvy Avatar answered Oct 10 '22 02:10

Buvy