Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework With mysql Database First

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.

like image 303
Rubemlrm Avatar asked May 08 '18 13:05

Rubemlrm


People also ask

Can Entity Framework be used with MySQL?

MySQL Connector/NET is compatible with multiple versions of Entity Framework Core. For specific compatibility information, see Table 7.2, “Connector/NET Versions and Entity Framework Core Support”.

How do I use database first approach in Entity Framework?

Step 1 − Let's create a new console project with DatabaseFirstDemo name. Step 2 − To create the model, first right-click on your console project in solution explorer and select Add → New Items… Step 3 − Select ADO.NET Entity Data Model from middle pane and enter name DatabaseFirstModel in the Name field.

Which is better code first or database first in Entity Framework?

Versioning databases is hard, but with code first and code first migrations, it's much more effective. Because your database schema is fully based on your code models, by version controlling your source code you're helping to version your database.


2 Answers

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 
like image 159
Nicole Davisson Avatar answered Sep 22 '22 12:09

Nicole Davisson


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.

like image 36
Anson Fong Avatar answered Sep 18 '22 12:09

Anson Fong