简体   繁体   中英

Entity framework database provider compatibility error

I am trying to use Entity framework to setup an ADO.net model using MYSQL DB following the instructions @ https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html,I installed the connector and stuck at the below error,I shared my App.config details aswell,can anyone help me on how to fix this error?

在此处输入图片说明

App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider><provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>
  </entityFramework>
<system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" name="MySQL Data Provider" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /></DbProviderFactories>
  </system.data></configuration>

Seems that these app.config lines below points directly to the problem source:

<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>

<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>

This means your machine has previous version of MySQL Connector .NET installed which also referenced inside configuration file (6.8.3.0), hence you need to uninstall previous version(s) of MySQL Connector .NET (also remove its EF provider string) first. Then, ensure references of MySql.Data.dll , MySql.Data.Entity.EF6.dll & MySql.Web.dll libraries being referenced to latest version (6.9.9.0) and entityFramework section in app.config should be look like this:

<entityFramework>
  <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
  <providers>
    <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  </providers>
</entityFramework>

Afterwards, clean and rebuild the project.

NB: You may try to replace MySQL libraries in \\Program Files\\Microsoft Visual Studio [version number]\\Common7\\IDE\\PrivateAssemblies with those in \\Program Files\\MySQL\\MySQL Connector Net 6.9.9\\Assemblies\\v4.5 if previous version assemblies still exist.

Related issue:

MySQL Connector with EF6 in Visual Studio 2013

You simply need to install EF6 package from NuGet into your project : https://www.nuget.org/packages/EntityFramework/

Then install MySQL.Data.Entity into your project (select the same version you have for you MYSQL NET connector installed on your laptop) : https://www.nuget.org/packages/MySql.Data.Entity/6.9.11

This solved it for me

Same problem with VS2019.

Installed versions:

  • Entity Framework 6.4.0
  • Mysql for VStudio 1.2.9
  • Mysql Connector/net 8.0.19
  • Nuget: Mysql.Data.EntityFramework 8.0.19
  • Nuget: Mysql.Data 8.0.19

Solution: after install those packages, close and restart visual studio, reinstall packages, etc and having the same error, what solved it was clean the solution and rebuild it. After that, the wizard worked as expected.

Important to have installed the same version of nuget packages and connector from Mysql. Also check app.config versions. Mine are:

<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />

<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.19.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
Install MySql for VS 1.2.9
Install MySql Connector 6.8.3

Add these Nuget Packages To your Project:

EntityFramework    //  6.4
Mysql.Data      //  6.8.8
Mysql.Data.Entities   // 6.8.3  
Mysql.Web  //   6.8.8

in Solution Explorer edit App.config:( Add or Replace):

    <entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
    <providers>
    <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
    </entityFramework>



    rebiuld and nothing more 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM