Store Enums as Strings in EF Core 6

Viewed 609

While looking for a solution to store all our enums as strings in the database, i came up with the following code.

protected override void ConfigureConventions(ModelConfigurationBuilder builder)
{
    builder.Properties(typeof(Enum))
        .HaveConversion<string>()
        .HaveColumnType("nvarchar(128)");
}

Doing some testing, this seems to work just fine, even for nullable enums. The limitation to 128 characters is completely optional, the default is nvarchar(max).

Since all other solutions around this topic require much more and complex code, i would like to know if there are any downsides to my rather simple approach?

0 Answers
Related