Entity Framework will not work with MySql

.net c# entity-framework-6 mysql visual-studio-2015

Question

I have visual studio community 2015 and I have a class library project. I have added the Entity Framework 6, Mysql.Data, MySql.Data.Entity and MySql.Net(not even sure this is needed) package through nuGet.

However when I go through adding an ADO.Net Entity Model to the project via the wizard I get as far as "Choose your version" but I get an error stating that "Your project references the latest version of Entity Framework; However, an Entity Framework database provider compatible with this version could not be found for your data connection......."

My App.config is as follows

<?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>
  <connectionStrings>
    <add name="MyContext" providerName="MySql.Data.MySqlClient" connectionString="server=localhost;port=3306;database=hapangodb;uid=root;password=********" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <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" />
    <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
      </provider></providers>
  </entityFramework>

<system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <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.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.6.4.0" newVersion="6.6.4.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

I have tried uninstalling and reinstalling all the mysql components but still get the same issue. I have been using Entity framework with mysql for years with no issues but since getting a new laptop I cant seem to get it to work......

What on earth is going on?

1
0
8/18/2015 10:15:08 PM

Accepted Answer

I have solved the issue (Why does it always seem like as soon as you start telling people about code issues you suddenly find them yourself?)

For some reason I had two mysql providers in the App.config. One was simply EF6 the other as you can see is more targeted to 6.9.7.0.

I removed the EF6 one along with the sql server provider (as I will not need it anyway) and now everything works.

I hazard a guess that if the two mysql providers had been the other way around then it would have worked too as it seems to have been trying the first one it came across.

0
8/18/2015 10:54:38 PM

Popular Answer

Configuration looks correct to me. Just for testing purpose, have you tried adding the below config to your machine.config file and see if that picks up?

<DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <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.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow