作者:byd888_613 | 来源:互联网 | 2022-12-15 14:00
我添加了一些模型,用于连接到SQL数据库,现在移植到MySQL.我跑的时候收到这个错误:dotnet ef update --context {context}
Blockquote System.NotImplementedException:'MySQLNumberTypeMapping'不支持值转换.对价值转换的支持通常需要更改数据库提供程序.Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.b__7_0的Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping.Clone(ValueConverter转换器)在Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMapping(MemberInfo成员)的ValueTuple 3 k)
at System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey键,Func 2 valueFactory)
at Microsoft.EntityFrameworkCore.Storage.RelationalTypeMappingSource.FindMappingWithConversion(RelationalTypeMappingInfo& mappingInfo, IReadOnlyList
1主体) )Microsoft.EntityFrameworkCore.Metadata上的Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyDiscoveryConvention.IsCandidatePrimitiveProperty(PropertyInfo propertyInfo),Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyDiscoveryConvention.Apply(InternalEntityTypeBuilder entityTypeBuilder),位于Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.在Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.Conventi的Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.RunVisitor.VisitOnEntityTypeAdded(OnEntityTypeAddedNode node)上的ImmediateConventionScope.OnEntityTypeAdded(InternalEntityTypeBuilder entityTypeBuilder).Microsoft的Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Run()中的Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.VisitConventionScope(ConventionScope节点)上的onDispatcher.ConventionVisitor.VisitConventionScope(ConventionScope节点). EntityFrameworkCore.Metadata.Conventions.Internal.RelationshipDiscoveryConvention.DiscoverRelationships(InternalEntityTypeBuilder entityTypeBuilder)...
'MySQLNumberTypeMapping'不支持值转换.对价值转换的支持通常需要更改数据库提供程序.
这是我希望创建的表格:(我删除了对DataType(*)或枚举的任何引用,但我可能是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不喜欢这些定义?或者它试图做的这个价值转换是什么?
1> Mitchell..:
为了继续开发,我找到了一个合适的解决方案
安装包Pomelo.EntityFrameworkCore.Mysql -version 2.1.0-rc1-final
使用nuget控制台并修改options.UseMySQL对options.UseMySql的任何引用.
这让我继续使用dotnet 2.1并使用了一个mysql数据库.
希望这可以帮助!