带有MySQL的EF6-datetime中的formatexception



我有这样编码的DB:

public class DBModel : DbContext
{
public DBModel()
: base("name=DBModel")
{
}
public virtual DbSet<Entry> Entries{ get; set; }
}
public class Entry
{
[Key]
public int Id { get; set; }
public DateTime EntryDate { get; set; }
public string EntryContent { get; set; }
public virtual Alarm Alarm { get; set; }
}
public class Alarm
{
[Key]
public int AlarmId { get; set; }
public DateTime AlarmDate { get; set; }
public bool Enabled { get; set; }
}

当我尝试更新数据库时,它以FormatException结束,堆栈如下:

System.FormatException: Nieprawidłowy format ciągu wejściowego.
w System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
w System.Convert.ToDouble(String value)
w MySql.Data.Entity.MySqlMigrationSqlGenerator.Generate(CreateIndexOperation op)
w MySql.Data.Entity.MySqlMigrationSqlGenerator.Generate(IEnumerable`1 migrationOperations, String providerManifestToken)
w System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)
w System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, VersionedModel sourceModel, VersionedModel targetModel, Boolean downgrading)
w System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.AutoMigrate(String migrationId, VersionedModel sourceModel, VersionedModel targetModel, Boolean downgrading)
w System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
w System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
w System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
w System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
w System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
w System.Data.Entity.Infrastructure.Design.Executor.Update.<>c__DisplayClass0_0.<.ctor>b__0()
w System.Data.Entity.Infrastructure.Design.Executor.OperationBase.Execute(Action action)

EF框架版本:6.4.4MySQL服务器版本:8.0.18MySQL插件:

  • MySQL.Data v6.10.9
  • MySQL数据版本6.10.9

如何修复?

这看起来像MySql.Data.EntityFramework中的一个错误,由以下行引起:https://github.com/mysql/mysql-connector-net/blob/f3b6ae6a416de898b25edc0062b25a2f6ea90291/EntityFramework/src/MySqlMigrationSqlGenerator.cs#L771

我猜_providerManifestToken包含一个类似"8.0"的字符串,但您的程序是在一个区域设置(pl pl?(中运行的,其中浮点数的格式类似8,0。因此,对Convert.ToDouble的区域性敏感调用失败。

您可以在上将其报告为错误https://bugs.mysql.com并等待修复。

或者,可以将Thread.CurrentCulture设置为en-US以运行迁移(Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");(,然后将其设置回。

最新更新