Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't use a MySQL connection for entity framework 6

I'm trying to use entity framework 6 with MySQL.

I did install MySQL plugin for visual studio 1.1.1 and MySQL .Net connector 6.8.3.

The problem is when I try to create a new ADO.NET Entity model, I can't choose MySQL for the connection.

enter image description here

But if I create a connection from the connection tool in visual studio, I can see MySQL

enter image description here

It means that the version currently installed is not compatible with entity framework 6. How is it possible after that I installed the latest connector and the plugin. Is there anything else to do?

Thank you

EDIT

I did a fresh install of MySQL without installing the default connector and then I installed the 6.8.3 and the plugin for visual studio.

Then I can see the connection I made for my Entity model but when I'm about to choose the entity version, I get this message.

enter image description here

like image 719
Marc Avatar asked Jan 18 '14 15:01

Marc


People also ask

Can Entity Framework work with MySQL?

MySQL Connector/NET integrates support for Entity Framework 6 (EF6), which now includes support for cross-platform application deployment with the EF 6.4 version.

Is Entity Framework 6 still supported?

Versions 6.0, 6.1, 6.2, and 6.3 are no longer supported. Although Entity Framework 6. x is still supported, it is no longer being developed and will only receive fixes for security issues.

Why is MySQL Connector not working?

The Python "ModuleNotFoundError: No module named 'mysql'" occurs when we forget to install the mysql-connector-python module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install mysql-connector-python command.

Can I use MySQL with Visual Studio 2022?

MySQL isn't supported for Visual Studio 2022 yet. it's weird and frustrating, to be honest, but if you want to work with MySQL with VS22, you either need to change the Database or go back to VS19.


2 Answers

Solution in 2017

Install Nuget Package:

Install-Package EntityFramework Install-Package MySql.Data.Entity -Version 6.9.9 

Install MySQL for Visual Studio 1.2.6   - https://dev.mysql.com/downloads/windows/visualstudio/

Changes in Web.Config

<EntityFramework> 

to:

<EntityFramework codeConfigurationType = "MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6"> 

Add (** your information **):

<connectionStrings> <add name="**YourContextName**" connectionString="server=**xxx.xxx.xxx.xxx**;port=3306;user id=**your user**;password=**your password**;database=**your database**" providerName="MySql.Data.MySqlClient" /></connectionStrings> 

**Restart Visual Studio**

My Settings:
- Microsoft Visual Studio Community 2015
- Dot Net Framework 4.5.2
- Asp.Net MVC 5.2.3.0
- MySql Server 5.6

like image 40
Edvaldo Silva Avatar answered Sep 20 '22 00:09

Edvaldo Silva


LATEST EDIT

The bug has been fixed.

Chris' comment:

2015-11-07 and you can now get it all working without editing any files or doing weird stuff. Use the MySQL for Windows installer and include the Visual Studio support and the latest Connector.Net. Be sure to update after installing and you will get the latest of each (1.2.5 and 6.9.8). Use NuGet to install EntityFramework, MySql.Data, and MySql.Data.Entity. Finally, built and enjoy code-first reverse engineering goodness by adding an Ado.Net Entity Model.

Original answer

I found out it's a bug from MySQL.

Here's the link explaining a workarround.

On your machine where VS 2013 is installed, VS plugin (1.1.3 GA) and Connector/Net

Close all VS instances before doing the steps.

On a Windows Explorer window go to this path or wherever you installed you Connector/net binaries

C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5\

Copy the file:

MySql.Data.Entity.EF6.dll

And paste it to this folder

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies

If it asks you to overwrite it please do so.

You'll need admin rights in order to overwrite the file.

Then you can try again to generate the script for your model.

It is important that you have the 1.1.3 version of the VS plugin installed since this workaround is for that.

Unfortunately it doesn't work for me, so I downgraded to entity framework 5 until they fix this.

EDIT

Finaly, it works now.

I had to add the 3 following DLLs :

  • C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5\MySql.Data.dll
  • C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5\MySql.Data.Entity.EF6.dll
  • C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5\MySql.Web.dll

Then I changed the EntityFramework part in the web config to :

<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">     <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />     <providers>       <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />      </providers>   </entityFramework> 

Don't forget to REBUILD and you should be able to create a entity framework 6 model with MySQL.

IMPORTANT

Make sure you have installed MySQL for visual studio 1.1.3 and MySQL connector .net 6.8.3

like image 110
Marc Avatar answered Sep 20 '22 00:09

Marc