Entity Framework With mysql Database First

10,327

Solution 1

So after struggling for 3 days myself I FINALLY found the problem...

So the MySql.Data and MySql.Data.Entity that you have to download from NuGet packages versions are directly correlated with the version of the MySql Connector/NET that have to download.

And when you go look the latest version of MySql.Data.Entity is 6.10.7, so this means when download Connector/NET 8 then there is a version incompatibility which results in the ADO.Net data entity wizard closing.

Download the following and BAM it works:

MySql for visual studio 
MySql Connector/NET v6.10.7   

NuGet packages:

Entityframework v6.1.3    
MySql.Data v6.10.7    
MySql.Data.Entity v6.10.7 

Solution 2

One thing worth to note:

You will need different Mysql EntityFramework Package for the Mysql version 6 and version 8. (This maybe why the poster has downgraded his/her mysql connector from 8 to 6)

If your mysql connector is version 8.x.x, You may need to install this NuGet Package: https://www.nuget.org/packages/MySql.Data.EntityFramework/

If you mysql connector is version 6.x.x you will need: https://www.nuget.org/packages/MySql.Data.Entity/

And install exactly the same version as your mysql connector. Otherwise, something will not work.

Solution 3

I was able to fix this problem with following config at Web.config

<entityFramework>
  <defaultConnectionFactory type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.EntityFramework, Version=8.0.11.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  <providers>
    <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.11.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
  </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=8.0.11.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D" />
  </DbProviderFactories>
</system.data>

Also I referenced to:

Solution 4

This is a issue with the version of the MySQL connector packages you are using. In my case, I am using MySQL.Data, MySQL.Entity and MySQL.Web from Nuget. If I use any version after 6.9.11 then I get the behavior you mention.

Share:
10,327
Rubemlrm
Author by

Rubemlrm

Perl Scripter Linux Lover A little otaku

Updated on June 21, 2022

Comments

  • Rubemlrm
    Rubemlrm almost 2 years

    i'm working in a new project with c# and we want to use entity framework 6 but everytime we want to generate the models based on the database we have in usage. But when i'm generating a ADO.Net model using the wizard, after i select the database and the entity framework i click on the "next" button and instead appear the window to select the tables , the windows disappear without any type of error.

    I'm using visual studio 2017 community edition and i've installed the mysql connector v.8.0.11. If i downgrade the mysql connector version and entity framework to v5 everything works without any problem, but after i update the connector and entity framework to version 6.* i get the problem i've reported above.

  • 7 Reeds
    7 Reeds about 6 years
    Your question is probably a duplicate of stackoverflow.com/questions/49036983/…
  • Rubemlrm
    Rubemlrm about 6 years
    When i do that everything works fine, but i lost access to Entity framework v6 and its a requirement for this project. In your case you are using v5 or v6 of entity framework?
  • 7 Reeds
    7 Reeds about 6 years
    Nuget tells me: 6.2.0
  • Rubemlrm
    Rubemlrm about 6 years
    If you dont mind can you try generate a model from database using that version ?
  • 7 Reeds
    7 Reeds about 6 years
    No problem. My test worked. In the linked answer above there is a bit about removing the default version of "MySQL for Visual Studio" and installing the the latest development version (2.0.5). Basically, I don't think Oracle actually tests the MySQL software it produces.
  • Rubemlrm
    Rubemlrm about 6 years
    tried following the steps of the link and got the same problem. But i will try test this steps on other pc, just to check if is something wrong with my setup.
  • 7 Reeds
    7 Reeds about 6 years
    Also, don't forget about rebooting your PC after the uninstalls/reinstalls. I seem to recall being extremely frustrated in this process and rebooted after each operation.
  • Jason Amoss
    Jason Amoss over 5 years
    I had to do this way as well. I think it has to do with the db version in my case.
  • Arash.Zandi
    Arash.Zandi over 5 years
    that worked for me and you can download the connector from here downloads.mysql.com/archives/c-net
  • Dhrumil Bhankhar
    Dhrumil Bhankhar about 5 years
    That was really helpful, I went for 6.10.8 version for connector & both packages. It worked!.. The thing is versions must be exactly same!
  • jing
    jing over 4 years
  • Daniel
    Daniel over 3 years
    What version of VS are you using? I'm able to see the Data Model wizard but it seems to crash and reopen the "Add Item" dialogue
  • Hicham O-Sfh
    Hicham O-Sfh over 3 years
    @Daniel this is exactly the problem that I had mentioned, it happens when you have at least one different version of the components , that's why I suggested on having the same versions, verify your app.config file, or try re-installing the correct version of each component . ps : I have Visual Studio 2019 (this works also for visual studio 2017 and 2015 #tested )