u/Tuckertcs

▲ 8 r/dotnet

Entity Framework randomly adding max-length to columns in migrations?

How do I tell EF that I don't want a max length?

In some configurations, I'll have something like this with two identical string columns:

builder
    .Property(x => x.Name)
    .IsRequired();

builder
    .Property(x => x.Description)
    .IsRequired(false);

However when I create the migration, it'll add 450 max-length to some columns, but not others:

...
Name = table.Column<string>(type: "nvarchar(450", nullable: false), // Why 450???
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
...

Why is this happening, and how can I fix this?

reddit.com
u/Tuckertcs — 19 hours ago