Entity framework database provider compatibility error

社会主义新天地 提交于 2021-02-09 14:00:28

问题


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>

回答1:


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




回答2:


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




回答3:


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"/>



回答4:


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 


来源:https://stackoverflow.com/questions/42565780/entity-framework-database-provider-compatibility-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!