Shane
Shane

Reputation: 790

MySQLNumberTypeMapping' does not support value conversions

I've added a few models that I used to connect to a SQL database with and are now porting to MySQL . I am getting this error when I run : dotnet ef update --context {context}

Blockquote System.NotImplementedException: The 'MySQLNumberTypeMapping' does not support value conversions. Support for value conversions typically requires changes in the database provider. at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping.Clone(ValueConverter converter) at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.b__7_0(ValueTuple3 k) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMappingWithConversion(RelationalTypeMappingInfo& mappingInfo, IReadOnlyList1 principals) at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMapping(MemberInfo member) at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyDiscoveryConvention.IsCandidatePrimitiveProperty(PropertyInfo propertyInfo) at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyDiscoveryConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder) at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder) at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.RunVisitor.VisitOnEntityTypeAdded(OnEntityTypeAddedNode node) at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.VisitConventionScope(ConventionScope node) at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.VisitConventionScope(ConventionScope node) at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Run() at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.RelationshipDiscoveryConvention.DiscoverRelationships(InternalEntityTypeBuilder entityTypeBuilder) ...

The 'MySQLNumberTypeMapping' does not support value conversions. Support for value conversions typically requires changes in the database provider.

Here's on of the tables im expected to get created: (I've removed any reference to DataType(*) or enums that I though might be the issue with MySQL.

[Key]
public int ID { get; set; }
[StringLength(50)]
public string Name { get; set; }
public int? PropertyID { get; set; }
public Property Property { get; set; }

//public SelectList Animals { get; set; }
//public string AnimalTypes { get; set; }
[Display(Name="Spesie")]
public int? AnimalTypeID { get; set; }
[Display(Name = "Spesie")]
public AnimalType AnimalType { get; set; }

public bool Male { get; set; }
public bool Trophy { get; set; }
public int Quantity { get; set; }
[DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "R{0:N}")]
public decimal Price { get; set; }
[StringLength(2000)]
public string Comments { get; set; }

Why is MySQL not liking these definitions? or what is this value conversions its trying to do?

Upvotes: 10

Views: 5347

Answers (3)

Chihuahua Enthusiast
Chihuahua Enthusiast

Reputation: 1580

I was able to fix this issue by upgrading MySQL.Data.EntityFrameworkCore from 6.10.8 to 8.015 (released 2/1/2019) and upgrading .NET Core from 2.0 to 2.2.

I believe the issue has been fixed in version 8.

Upvotes: 1

Kowalchick
Kowalchick

Reputation: 448

In order to continue development I found a suitable solution was to

Install-Package Pomelo.EntityFrameworkCore.Mysql -version 2.1.0-rc1-final

using nuget console and modify any reference of options.UseMySQL to options.UseMySql.

This allowed me to continue with dotnet 2.1 and utilize a mysql database.

Hope this helps!

Upvotes: 18

MUG4N
MUG4N

Reputation: 19717

The MySQL data provider does not implement the value conversion feature. You are getting this exception because you are using enums as data types which must be converted by the MySQL data provider which does not implement this feature and therefore throws a NotImplementedException.

This bug has already been reported: https://bugs.mysql.com/bug.php?id=89855

There is also an open github issue: https://github.com/aspnet/EntityFrameworkCore/issues/11078

In short, MySQL.Data.EntityFrameworkCore, running on .Net Core 2.0, does not function correctly while using Microsoft.EntityFrameworkCore.Relational 2.1.0-preview1-final, despite claims that 2.0 conformant providers should work on it.

Upvotes: 2

Related Questions