I was able to store an enum as a string in the database.
builder.Entity(eb =>
{
eb.Property(b => b.Stage).HasColumnType(\"varchar(20
You can use this to convert all the Enum of all the properties of all the entities into a string and vice versa :
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using System;
namespace MyApp
{
public class DatabaseContext : DbContext
{
public DbSet Users { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// Configure your model here
}
protected override void OnModelCreating(ModelBuilder model)
{
foreach (var entityType in model.Model.GetEntityTypes())
{
foreach (var property in entityType.GetProperties())
{
if (property.ClrType.BaseType == typeof(Enum))
{
var type = typeof(EnumToStringConverter<>).MakeGenericType(property.ClrType);
var converter = Activator.CreateInstance(type, new ConverterMappingHints()) as ValueConverter;
property.SetValueConverter(converter);
}
}
}
}
}
}