I have an entity with two enums and I've set a conversion for these two fields to save the string in the database. But when I generate the migration, EF Core creates one column with nvharchar(max) and the other with nvarchar(450).
public enum FirstType
{
Indexing,
Reading,
}
public enum SecondType
{
ProposalAutomationContent,
NoticeResumeInteraction,
}
var processTypeConverter = new EnumToStringConverter<ProcessType>();
var aiActionTypeConverter = new EnumToStringConverter<AiActionType>();
modelBuilder
.Entity<AiTokenUsage>()
.Property(e => e.ProcessType)
.HasConversion(processTypeConverter);
modelBuilder
.Entity<AiTokenUsage>()
.Property(e => e.ActionType)
.HasConversion(aiActionTypeConverter);
ActionType = table.Column<string>(type: "nvarchar(max)", nullable: false),
ProcessId = table.Column<long>(type: "bigint", nullable: false),
ProcessType = table.Column<string>(type: "nvarchar(450)", nullable: false)
I tried adding a big enum option to one of the enums but EF Core now generates both columns with nvarchar(450).
How does EF Core decides the column length? And why does it have this behaviour?