UsingMySQLConnector. NET6.6.4withEntityFramework5-_ MySQL

Source: Internet
Author: User
UsingMySQLConnector. NET6.6.4withEntityFramework5 I had been waiting for the latest MySQL connector. 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 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: cocould 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.