EF Core 3 pre-defined enum to string value conversion throws exception
Posted: Wed 18 Dec 2019 14:16
Using the pre-defined enum to string value conversions as shown in the Microsoft docs does not work anymore using EF Core 3. It worked fine in EF Core 2.1.
When explicitly creating an EnumToStringConverter instance and assigning that as the converter, it does work.
Any query on BeastRider throws the following exception:
Reproduced with versions:
When explicitly creating an EnumToStringConverter instance and assigning that as the converter, it does work.
Code: Select all
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<BeastRider>().ToTable("BEAST_RIDER");
modelBuilder.Entity<BeastRider>().HasKey(_ => _.Id);
modelBuilder.Entity<BeastRider>().Property(_ => _.Id).HasColumnName("ID");
modelBuilder.Entity<BeastRider>().Property(_ => _.RiderName).HasColumnName("RIDER_NAME");
modelBuilder.Entity<BeastRider>().Property(_ => _.Beast).HasColumnName("BEAST_TYPE");
// Does not work
modelBuilder.Entity<BeastRider>().Property(_ => _.Beast).HasConversion<string>();
// Works
//var converter = new EnumToStringConverter<EquineBeast>();
//modelBuilder.Entity<BeastRider>().Property(_ => _.Beast).HasConversion(converter);
}
A repository reproducing the issue can be found here.System.InvalidOperationException: No coercion operator is defined between types 'System.String' and 'EquineBeast'.
Reproduced with versions:
- Devart.Data.Oracle.EFCore: 9.9.887
- Microsoft.EntityFrameworkCore.Relational: 3.0.1 & 3.1.0
- .NET Core SDK: 3.0.101 & 3.1.100
- .NET Core Runtime: 3.0 & 3.1