本文介绍了MySQLNumberTypeMapping' 不支持值转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了一些模型,我曾经用它们连接到 SQL 数据库,现在正在移植到 MySQL .运行时出现此错误:dotnet ef update --context {context}

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}

块引用System.NotImplementedException:MySQLNumberTypeMapping"不支持值转换.对价值转换的支持通常需要更改数据库提供程序.在 Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping.Clone(ValueConverter 转换器)在 Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.b__7_0(ValueTuple3 k)在 System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)在 Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMappingWithConversion(RelationalTypeMappingInfo& mappingInfo, IReadOnlyList1 principals)在 Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMapping(MemberInfo 成员)在 Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyDiscoveryConvention.IsCandidatePrimitiveProperty(PropertyInfo propertyInfo)在 Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyDiscoveryConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder)在 Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder)在 Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.RunVisitor.VisitOnEntityTypeAdded(OnEntityTypeAddedNode 节点)在 Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.VisitConventionScope(ConventionScope 节点)在 Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.VisitConventionScope(ConventionScope 节点)在 Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Run()在 Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.RelationshipDiscoveryConvention.DiscoverRelationships(InternalEntityTypeBuilder entityTypeBuilder) ...

MySQLNumberTypeMapping"不支持值转换.对价值转换的支持通常需要更改数据库提供程序.

这是我希望创建的表:(我已经删除了对 DataType(*) 或枚举的任何引用,我认为这可能是 MySQL 的问题.

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; }

为什么 MySQL 不喜欢这些定义?或者这个价值转换它试图做什么?

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

推荐答案

为了继续开发,我找到了一个合适的解决方案

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

安装包 Pomelo.EntityFrameworkCore.Mysql -version2.1.0-rc1-final

使用 nuget 控制台并将 options.UseMySQL 的任何引用修改为 options.UseMySql.

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

这让我可以继续使用 dotnet 2.1 并使用 mysql 数据库.

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

希望这有帮助!

这篇关于MySQLNumberTypeMapping' 不支持值转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 23:20