Enable Entity Framework 6 for MySql (C#) in WinForms of Microsoft Visual Studio 2013
First of all, we don't even need to install the mysql-installer-community-5.7.3.0-m13.msi.
- Install the latest mysql-visualstudio-plugin
- Install the latest mysql-connector-net
- New C# .Net 4.5 Framework WinForms (for 4.0 it should work based on Does Entity Framework 6 support .NET 4.0? )
- 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.
MySQL Connector with EF6 in Visual Studio 2013
Basic solution is to reinstall MySQL and VisualStudio including Entity and .NET.
For some reason, I am not certain why, the installation process corrupts the DLLs, or at least that is the experience I had and other colleagues. Our solution has been to try all of above with to no avail. So in the end we tried to reinstall, and it worked. So try that :)
Could not connect to MySQL through EF6 in Visual Studio 2013
This worked for me WITHOUT reinstalling the Visual Studio or anything what so ever.
- installed latest MySQL visual studio plugin and MySQL connector net
- removed the entityFramework Tag in App.config or Web.config and all its child tags.
- replaced it with the following code:
<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" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
Adding ADO.Net Entity Framework gives The project's target framework does not contain Entity Framework runtime assemblies
I know that almost all the other answers recommends to change the target framework, but some users (including me) needs to use .NET 6.0
instead of .NET Framework
, so that solution its not valid for us.
I was able to create the models by using Paul Sinnema's link and using SQL authentication instead of Windows Auth (in my case):
You will need to install the following packages from NuGet:
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Afted that run the following command in the Package Manager Console:
(Tools>Nuget Package Manager>Package Manager Console)
PM> Scaffold-DbContext "Server=.\LOCAL_SERVER;User ID=YOUR_DB_USER;Password=YOUR_DB_PASSWORD;Database=YOUR_DATABASE;Trusted_Connection=False;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
Related Topics
How Much Faster Is C++ Than C#
How to Keep a .Net Console App Running
How to Correctly Prefix a Word with "A" and "An"
Variables Within App.Config/Web.Config
How to Seed an Admin User in Ef Core 2.1.0
How to Round Up Value C# to the Nearest Integer
How to Deserialize a Unix Timestamp (Μs) to a Datetime from JSON
C# an Established Connection Was Aborted by the Software in Your Host MAChine
Capturing Mouse/Keyboard Events Outside of Form (App Running in Background)
Why Is Typedreference Behind the Scenes? It's So Fast and Safe... Almost Magical!
Simple Animation Using C#/Windows Forms
C# Entity-Framework: How to Combine a .Find and .Include on a Model Object
Why Does Wcf Return Myobject[] Instead of List<T> Like I Was Expecting
The Name "Xyz" Does Not Exist in the Namespace "Clr-Namespace:Abc"
Hashset That Preserves Ordering
Openxml Sdk Returning a Number for Cellvalue Instead of Cells Text