Page 1 of 1

EF Core 3 pre-defined enum to string value conversion throws exception

Posted: Wed 18 Dec 2019 14:16
by laurensb
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.

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);
}
Any query on BeastRider throws the following exception:
System.InvalidOperationException: No coercion operator is defined between types 'System.String' and 'EquineBeast'.
A repository reproducing the issue can be found here.

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

Re: EF Core 3 pre-defined enum to string value conversion throws exception

Posted: Thu 26 Dec 2019 14:17
by Shalex
Thank you for your report. We will notify you when the issue is fixed.

Re: EF Core 3 pre-defined enum to string value conversion throws exception

Posted: Mon 20 Jan 2020 08:57
by Thomasdc
Any news on this? Any ETA of a fix?

Re: EF Core 3 pre-defined enum to string value conversion throws exception

Posted: Wed 22 Jan 2020 16:49
by Shalex
The bug with using value converters detected automatically by .HasConversion<string>() in EF Core 3 is fixed. The internal build with the fix: https://download.devart.com/nuget_oracle_9_10_929.zip.

Re: EF Core 3 pre-defined enum to string value conversion throws exception

Posted: Sun 09 Feb 2020 17:44
by pergardebrink
Shalex wrote: Wed 22 Jan 2020 16:49 The bug with using value converters detected automatically by .HasConversion<string>() in EF Core 3 is fixed. The internal build with the fix: https://download.devart.com/nuget_oracle_9_10_929.zip.
Sorry for hijacking this thread, but does this apply to Devart with EFCore 3 and MySql as well? I get an System.InvalidOperationException and the message:

Code: Select all

No coercion operator is defined between types 'System.Byte' and 'System.Boolean'.
If so, is there a internal build for dotConnect as well that I could try? Or when is the next version expected to be released (I need both the netstandard2.1 and net461 versions of the MySql EFCore3 driver, as the net461 version on NuGet is for EF Core 2 and was only included in the dotConnect package)

Re: EF Core 3 pre-defined enum to string value conversion throws exception

Posted: Mon 10 Feb 2020 17:56
by Shalex
pergardebrink wrote:does this apply to Devart with EFCore 3 and MySql as well?
Yes, it does. The internal build of dotConnect for MySQL with the fix: https://download.devart.com/nuget_mysql_8_16_1575.zip.

If you need the installation of v8.16.1575 for getting .NET Framework version of the assemblies, contact us and specify your email used when registering the product.

We are planning to release public builds next week.

Re: EF Core 3 pre-defined enum to string value conversion throws exception

Posted: Mon 02 Mar 2020 17:32
by Shalex
The bug with using value converters detected automatically by .HasConversion<string>() in EF Core 3 is fixed.
The new public builds of dotConnect providers are released.