Using MySQL Connector .NET 6.6.4 with Entity Framework 5 -_MySQL
Now it was time to let the code first magic happen. I create my models and then issue an Enable-Migration via the package manager console. The migrations are setup. Next I issue the Add-Migration Initial to create the initial scaffolding for my model and I get the following error:
No MigrationSqlGenerator found for provider ‘MySql.Data.MySqlClient’. Use the SetSqlGenerator method in the target migrations configuration class to register additional SQL generators.
Upon doing some research I find out that for the connector version 6.6.4, we’ll have to explicitly set up the SQL code generator. Open Configuration.cs file found in the Migrations folder and add the following line to the constructor
publicConfiguration(){AutomaticMigrationsEnabled=false; // register mysql code generatorSetSqlGenerator("MySql.Data.MySqlClient",newMySql.Data.Entity.MySqlMigrationSqlGenerator());}
After doing that I re-run my Add-Migation Initial command and the scaffolding is generated without any issues this time.
It is time to create the schema and tables. I issue Update-Database -Verbose command now and stumble upon another issue this time which is:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.IO.FileLoadException: Could not load file or assembly ‘EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0×80131040)
Upon more research I find out that connector 6.6.4 will not work with Entity Framework 5 but with Entity Framework 4.3. So to downgrade issue the following commands in the package manager console:
Uninstall-PackageEntityFramework Install-PackageEntityFramework-Version4.3.1 |
Finally I do Update-Database -Verbose again and voila! The schema and tables are created. Wait for the next version of connector to use it with Entity Framework 5.
推荐阅读
-
ABP .Net Core Entity Framework迁移使用MySql数据库
-
MySQL Connector Net 6.6.5 Entity Framework 显式预加载 Eager_MySQL
-
MySQL Connector Net 6.6.5 Entity Framework 显式预加载 Eager_MySQL
-
MySQL Connector/Net 6.6.4 发布_MySQL
-
MySQL Connector/Net 6.6.4 发布_MySQL
-
Using MySQL Connector .NET 6.6.4 with Entity Framework 5 -_MySQL
-
Using MySQL Connector .NET 6.6.4 with Entity Framework 5 -_MySQL
-
ABP .Net Core Entity Framework迁移使用MySql数据库