Enable Entity Framework 6 for MySql (C#) in WinForms of Microsoft Visual Studio 2013

70,887

Solution 1

First of all, we don't even need to install the mysql-installer-community-5.7.3.0-m13.msi.

  1. Install the latest mysql-visualstudio-plugin
  2. Install the latest mysql-connector-net
  3. New C# .Net 4.5 Framework WinForms (for 4.0 it should work based on Does Entity Framework 6 support .NET 4.0? )
  4. Install 4 Nuget Packages (follow sequence, if you install Mysql.Data.Entities before EntityFramework, it will resolve dependency and install EntityFramework 6.0.2 but what we need is EntityFramework 6.1.0)

EntityFramework

Mysql.Data

Mysql.Data.Entities

Mysql.Web

5.If you have tag entityFramework in App.config, please comment it and insert new tag entityFramework in App.config after tag startup

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

6.Add ADO.NET Entity Data Model (as mentioned in question)

7.After Entity Connection string is generated (as mentioned in question) and Tick Save entity connection settings in App.Config as then click Next

8.Choose Your Database Object and Settings (Tables, Views, or Stored Procedures and Functions) (Don't have "Which version of Entity Framework do you want to use?" because I have only one Entity Framework 6.0 provider so direct skip the selection if my only provider is valid)

9.Finish

Congratulations ^^

By the way, you may need to add the .dll files

  • MySql.Data.dll
  • MySql.Data.Entity.EF6.dll
  • MySql.Web.dll

inside this folder

C:\Program Files\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5 (32bit windows)

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

as your project reference for further EF6 functions.

Solution 2

I followed the instructions given by V-Shy and was having the same problem as LaRae White with the wizard shutting down on me. I'm running VS2015 and had just used the MySql installer to update to MySQL for Visual Studio v1.2.6 and Connector/NET v6.9.8.

What I eventually did to get it to work was this:

  1. Uninstall all the packages I had previously installed to solve this issue (EntityFramework, Mysql.Data, Mysql.Data.Entities, Mysql.Web)
  2. Added the following references found in C:\Program Files (x86)\MySQL\Connector.NET 6.9\Assemblies\v4.5 manually: MySql.Data.dll, MySql.Data.Entity.EF6.dll, and MySql.Web.dll

I hope that helps someone out.

Solution 3

The fix is as follows:

  1. Install MySQL Visual Studio Plugin
  2. Install MySQL Connector for .NET
  3. Add references in project from MySQLConnector Assemblies inside Program Files.
  4. Remove old code from App.Config or Web.Config

    <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="mssqllocaldb" /> </parameters> </defaultConnectionFactory> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework>

  5. Replace with code given below:

    <entityFramework> <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6"> </defaultConnectionFactory> <providers> <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" /> </providers> </entityFramework>

  6. Rebuild the project and try adding new ADO .NET Entity Data Model

Solution 4

I spend entire day figuring out how to solve this problem and nothing helps. Apparently i figure out 1 things about which people don't mention

In the model.edmx properties there is entire "DDL Generation Template", by default it set to "SSDLToSQL10.tt (VS)" but need to be set to "SSDLToMySQL.tt (VS)"

What is more it was also producing an error:

Running transformation: System.NullReferenceException: Object reference not set to an instance of an object.
bla bla bla
line 93 c:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen\SSDLToMySQL.tt

What leads me to the official bug in "MySQL for Visual Studio 1.1.3" which will be fixed in next build 1.1.4 which is not available so far.

However there is workaround fix:
Overwrite the "MySql.Data.Entity.EF6.dll" in
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies
by file from NET Connector in
C:\Program Files (x86)\MySQL\MySQL Connector Net 6.8.3\Assemblies\v4.5\

Solution 5

None of these answers solved it for me. The only thing that worked was to install MySql.Data.EntityFramework NuGet package. I restarted VS, rebuilt and was then able to get through the wizard. (WPF in VS2017 15.8.7).

Share:
70,887

Related videos on Youtube

V-SHY
Author by

V-SHY

Open Stackoverflow like starting a game for me, a network game that can help each other and level up by helping others~ knowledge and uncommon error can be discovered also from here. if ( "Stackoverflow" == "game") { knowledge.programming.obtain.difficulty = 0; }

Updated on July 09, 2022

Comments

  • V-SHY
    V-SHY almost 2 years

    Yesterday I knew that Entity Framework is another method to access database beside using Dataset or DataReader,then I tried to make Entity Framework 6 work for my MySql database server in MVS 2013.

    I open a WinForms with .Net FrameWork 4.5.1. (so I only have App.config but no app/web config in the project) After I installed mysql-installer-community-5.7.3.0-m13.msi and

    install EntityFramework package via

    TOOLS menu -> Library Package Manager -> Manage NuGet Packages for Solution... -> Online -> (Search) EntityFramework (beware of version of this package and it should be version 6.0.2, if not then click Updates -> EntityFramework to update)

    When I tried to add ADO.NET Entity Data Model via

    Right click Project -> Add -> New Item -> ADO.NET Entity Data Model -> Generate from Database -> New Connection -> Data sources: -> Change...-> MySQL Database -> Fill in the Server name with server IP, Username and Password -> Choose the Database name-> Test Connection -> OK

    Then Entity Connection string is generated -> Tick Save entity connection settings in App.Config as -> Next> ->

    Which version of Entity Framework do you want to use? Have option Entity Framework 6.0 but you cannot use it because

    "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. Exit this wizard, install a compatible provider, and rebuid your project before performing this action".

    How to solve this?

    By the way , if you install Entity Framework version 5 in Nuget Package then you might have option Entity Framework 5.0 here and you might success to use Entity Framework 5 but not the version 6.

  • Erico Souza
    Erico Souza over 9 years
    I had the same problem and followed your answer and managed to solve. Thank you
  • crokusek
    crokusek over 9 years
    It may impose the EF5 limit if the reference for "EntityFramework.SqlServer" (1 of 2 added by NuGet) is removed. Verified in MSVS2013, EntityFramework 6.1.1, .NET 4.5.2. MySql 6.9.4
  • crokusek
    crokusek over 9 years
    Deleting prior connection strings in the App.Config worked for me.
  • pikausp
    pikausp over 9 years
    Thanks a lot man, the DDL template was causing it for me as well!
  • Rafael Herscovici
    Rafael Herscovici about 9 years
    This is a great solution for the wrong question. The OP said that he can NOT generate edmx file, while your answer continues from after generating the edmx file.
  • Jimmyt1988
    Jimmyt1988 almost 9 years
    I LOVE YOU! Solved it for me you sexy little diva you!
  • K. Alan Bates
    K. Alan Bates over 8 years
    (Had MySQL working with EF6 using an old connector, but don't remember which version) I can confirm that this approach worked for me with MySQL Connector Net 6.9.7, MySQL for Visual Studio 1.2.3, and Entity Framework 5. "Absence of evidence..." and all that jazz, but I couldn't figure out any way to get EF6 to work with the updated connector and found myself in a situation where I had meddled with something that prevented me from going back to my working configuration (i.e. I forgot how and couldn't find the right information)
  • LaRae White
    LaRae White over 8 years
    This got me through, but now after step 7, for me it just closes out of the whole EF wizard and I have to start all over as if it errored out or something. Any ideas?
  • V-SHY
    V-SHY over 8 years
    If the error message can be included, then may be we can find some hints to solve it
  • James Wilkins
    James Wilkins about 8 years
    I had the same issue with the wizard just closing and nothing happening. I uninstalled all those packages as well, but for step 2 I simply re-installed all the packages again and it worked fine. I prefer to keep NuGet references in case other developers on the team jump in. ;)
  • James Wilkins
    James Wilkins about 8 years
    For those converting an existing project, I had to uninstall ALL packages listed above (in reverse order), then reinstall them again. I tried upgrading, but ended up with the ADO Entity wizard closing without doing anything (possibly a silent crash).
  • Worthy7
    Worthy7 almost 8 years
    The key point here is to make sure you install Microsofts Entity Framework package BEFORE the database provider one. Otherwise things seem to break.
  • John M
    John M almost 8 years
    I tried the Nuget re-install and it didn't work. Doing a manual install of the 3 class libraries did get it working.
  • Moby
    Moby almost 8 years
    Thank you, I had installed the connector and supporting software, added the provider settings, the inherited DbContext, etc. but still couldn't see this as a data provider when trying to create a ADO.net entity data model - adding the attribute annotation above solved the problem.
  • Luke
    Luke almost 8 years
    Great to hear that this helped someone, it sent me potty until I realised!
  • Sam Hobbs
    Sam Hobbs over 7 years
    @v-shy, I have the same problem as LaRae White. There are no error messages or anything like that, the wizard just goes away. I installed the 4 Nuget Packages in the specified order then I replaced the entityFramework tag in the app.config.
  • Sam Hobbs
    Sam Hobbs over 7 years
    @ih303, I was having the same problem. I did as described here. Then there was no connection string, so I left the references and re-installed the packages. Then I was back to the problem of the wizard going away.
  • V-SHY
    V-SHY over 7 years
    @user34660, Try to follow solution of @ih303?
  • Sam Hobbs
    Sam Hobbs over 7 years
    @v-shy, I did try and posted a comment there. I eventually gave up and went back to SQL Server. Microsoft makes stuff so complicated that MySQL's use of their stuff can break easily so I am stuck having to use all Microsoft stuff.
  • Harald Coppoolse
    Harald Coppoolse about 7 years
    Alas, although the change made that I saw both MySql and SQL Express databases, the wizard still disappears (VS 2015, everything newest version state Feb 2017)
  • Harald Coppoolse
    Harald Coppoolse about 7 years
    Unclear: in Feb 2017 there are two MySql.ConnectorNet packages: MySql.ConnectorNet.Data and MySql.ConnectorNet.Entity. Installing either of them or both of them didn't help, the wizard just disappears.
  • mRozwold
    mRozwold about 7 years
    @HaraldCoppoolse Sorry to hear that. I may help you with TeamViewer if you want. Normally I don't do that, but THIS PROBLEM was so damn annoying. The current problem is that I can't remember very well what I did^^. I did it one month ago with my project partner who had the same issue and I solved it in under 10 minutes.
  • Francisco G
    Francisco G almost 7 years
    Thanks! you saved me! :)
  • Whirlwind
    Whirlwind almost 7 years
    Very annoying @HaraldCoppoolse I have experienced the same issue.
  • Moshe
    Moshe almost 7 years
    Eventually I got it working with Nuget without adding any references manually. The problem is that you should reference Mysql.Data.Entity and not Mysql.Data.Entities.
  • K. Meke
    K. Meke almost 7 years
    Thank you - this is the only thing that worked for me - and I hate that it worked for me! Why does this work? Are the nuget packages broken somehow?
  • Max Szczurek
    Max Szczurek over 6 years
    I had the same problem as LaRae White - wizard just disappearing. I used Nuget to remove MySQL.Data.Entities, added MySQL.Data.Entity, updated the web.config with the entityFramework section in this post, rebuilt, and then it worked.
  • James Wilkins
    James Wilkins over 6 years
    FYI: Seems I ran into this again over a year later, and missed step 5 - really important!!! Otherwise you'll get an error in the connection wizard about not able to find compatible providers. :/
  • Nils Guillermin
    Nils Guillermin about 6 years
    This is still not working for me with VS2017. Has anyone ever gotten it to work trying something different?
  • William T. Mallard
    William T. Mallard over 5 years
    The rebuild part is what I needed. The hard part was getting a clean build without the model in place, lots of massive commenting-out!
  • Ginkgo
    Ginkgo over 5 years
    It is very important to match the NuGet and connector versions. That made the closing screen issue go away for me.
  • Muhammad Inaam Munir
    Muhammad Inaam Munir about 5 years
    I tried all above solution but nothing worked. Only this worked for me in VS 2017