![](/img/trans.png)
[英]FormatException when using multiple Include() methods in MySQL Linq Query EF6
[英]EF6 with MySQL - formatexception in datetime
我有這樣的數據庫編碼:
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.4 MySQL 服務器版本:8.0.18 MySQL 插件:
如何解決?
This looks like a bug in MySql.Data.EntityFramework, caused by this line: https://github.com/mysql/mysql-connector-net/blob/f3b6ae6a416de898b25edc0062b25a2f6ea90291/EntityFramework/src/MySqlMigrationSqlGenerator.cs#L771
我猜_providerManifestToken
包含類似"8.0"
的字符串,但是您的程序在浮點數格式為8,0
的語言環境(pl-PL?)中運行。 因此,對Convert.ToDouble
的區域性敏感調用失敗。
您可以在https://bugs.mysql.com將其報告為錯誤並等待修復。
或者,可以將Thread.CurrentCulture
設置為en-US
以運行遷移( Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
),然后再將其設置回來。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.