Using MySQL Connector .NET 6.6.4 with Entity Framework 5
2014-04-29 04:51
302 查看
I had been waiting for the latest MySQL connector for .NET to come out so I can move on to the new and sleek Visual Studio 2012 for my projects. Found out connector 6.6.4 has been out which can work with VS2012 so I happily install it. I start a brand new project and start setting up the Membership and Roles using the MySQL Website Configuration tool and everything worked great. To give you some more additional info about the project setup it is targeting .NET Framework 4 and the type of project is a MVC 3 web application using Razor.
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 generator SetSqlGenerator("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:
1 2 3 | Uninstall-PackageEntityFramework Install-PackageEntityFramework-Version4.3.1 |
相关文章推荐
- [转]Using the Repository Pattern with ASP.NET MVC and Entity Framework
- Lerning Entity Framework 6 ------ A demo of using Entity framework with MySql
- ASP.NET Entity Framework with MySql服务器发布环境配置
- Using stored procedures with ADO.NET entity framework
- http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
- Using the Repository Pattern with ASP.NET MVC and Entity Framework
- Entity Framework with MySQL 学习笔记一(关系整理版)
- Entity Framework with MySQL 学习笔记一(复杂类型 Complex Types)
- Using MySQL in .NET Framework
- Using Repository and Unit of Work patterns with Entity Framework 4.0
- Entity Framework With Mysql 之Code First
- No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClie
- [导入]using MySQL 5 with ObjectDataSources in ASP.NET 2.0
- Entity Framework with MySQL 学习笔记一(验证标签)
- WMI005-WMI学习笔记(五)——Using WMI with the .NET Framework(.NET框架使用WMI)
- Entity Framework with MySQL 学习笔记一(拦截)
- Entity Framework with MySQL
- Using StructureMap with the ASP.NET MVC framework
- 源码学习之ASP.NET MVC Application Using Entity Framework
- C# Entity Framework with MSSQL, MYSQL