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

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
laurensb
Posts: 13
Joined: Thu 06 Jun 2019 07:44

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

Post by laurensb » 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.

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

Shalex
Site Admin
Posts: 9105
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Thu 26 Dec 2019 14:17

Thank you for your report. We will notify you when the issue is fixed.

Thomasdc
Posts: 19
Joined: Sat 07 Jul 2018 14:20

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

Post by Thomasdc » Mon 20 Jan 2020 08:57

Any news on this? Any ETA of a fix?

Shalex
Site Admin
Posts: 9105
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » 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.

pergardebrink
Posts: 6
Joined: Mon 02 Jul 2018 08:26

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

Post by pergardebrink » Sun 09 Feb 2020 17:44

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)

Shalex
Site Admin
Posts: 9105
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Mon 10 Feb 2020 17:56

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.

Shalex
Site Admin
Posts: 9105
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Mon 02 Mar 2020 17:32

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.

Post Reply