in

Entity Framework with MySql is easy to install and work with. Learn More

Entity Framework with MySql is easy to install and work with. Learn More about Installing Entity Framwork with Mysql. Use Visual Studio with ASP.NET MVC

entity framework with mysql

Entity Framework with MySql: In this post, we will learn MVC with Entity Framework with MySql database.  We are used to connecting SQL server with Asp.net project but today we will connect MySql with asp.net project using Entity Framework.  Using Entity Framework with MySql we are able to perform the important Create, Read, Update and Delete operations in Mysql.

Quick Links:

There are free community versions available that we can use for this post.  Please follow the instructions to install the software and get started.

Install MySql for Windows:

Before we get started we need to install 4 important software.  They are:

  1. MySql for windows.
  2. MySql for Visual Studio.
  3. MySql connector
  4. Mysql Workbench.

Following the given steps will help us install the above software also.

  •  Search on the internet for MySql installer for Windows.
search mysql installer
search mysql installer
  • Click on MySql Server links shown in the image.
Select MySql Server
Select MySql Server
  • Now Click on MySql Community Server 5.7
Select Server version
Select Server version
  • Scroll down until you find the link to download the MSI (Microsoft Installer).  And click on that.  The link says, Go to download page
go to download page
go to download page
  • In the new page. Select for the MSI installer.  Please note that the other one is a web installer.  We need the MSI installer to continue with the tutorial.
Select MSI installer
Select MSI installer
  • After downloading the installer.  Double click on it and install it.
Launch the MSI
Launch the MSI
  • Now click on agree and click on the Next button.
Agree to license
Agree to license
  • Expand the node until you see the MySql Server node.  Select the MySql node that you want to install and click on the right arrow.
Select MySql Server
Select MySql Server
  • Expand the node to select MySql for Visual Studio and select the right version.  Now click on the right arrow to select this item as well.
MySql with Visual Studio
MySql with Visual Studio
selecting the MySql for Visual Studio
selecting the MySql for Visual Studio
  • Expand the node that says Connector/NET
  • Click on the right arrow after selecting the latest version.
Connector for .NET
Connector for .NET
  • Click on the Next on the bottom right.
Next on the bottom right
Next on the bottom right
  • Now click on Execute.
Execute the selected packages
Execute the selected packages
  • Choose Standalone MySql Server and click on Next.
Execute the selected packages
standalone package and click on next
  • Click on Next
Next
Next
  • Enter a new password and click on next.
enter a new password and re-enter password
enter a new password and re-enter password
  • Now Click on Next.
click on next
click on next
  • Click on Execute.
click on execute
click on execute
  • Click on Finish.
click on finish
click on finish
  • And click on Next.
Next
Next
  • Finish.
finish
finish
  • After successfully installing the above software.  We will see the following software on the Programs and features as shown in the image.
list of installed software
list of installed software

If there is something missing, please follow the instructions again and install the necessary software before proceeding with the tutorial.

after installing the above-mentioned software please continue down the tutorial.

Create a new ASP.net MVC application:

To make use of the installed applications, we need to incorporate them in our projects.  For tis purpose, let us start by creating a new project in Visual Studio that will make use of the above applications.

  • go to visual studio create a new project by selecting ctrl+shift+n
  • and select a new MVC application
New MVC application
New MVC application
  • Select an empty project and check mark MVC and then click on ok
choose mvc
choose mvc
  • In the solution explorer, we can see a new application.
  • We need to add a reference from MySql from the installed folder.
  • Right click on references browse
  • The location for the DLLs is given below.

C:\Program Files (x86)\MySQL\Connector NET 8.0\Assemblies\v4.5.2

  • Select the following DLL and add it to the project.

MySql.Data.DLL

MySql.Data.Entity.EF6.DLL

MySql.Web.DLL

adding the DLL
adding the DLL
Add the DLLs to the project
Add the DLLs to the project

We can do create update delete and read with MySQl server in this project

Using MySql Workbench:

In this tutorial, we are going to use MySql Workbench for GUI with our database.

We can create a new schema using the instructions given below.

  • Click on the local connection and connect to the server after entering the password.
new connection
new connection
  • Right click on the area shown in the image and select create schema.
creating new schema
creating new schema
  • In the field shown in the image, enter the name for the new schema.
Enter name for new schema
Enter name for new schema
  • Click on apply.
click on apply
click on apply
  • Click on apply.
apply
apply
  • Finish
entity framework with mysql
entity framework with mysql

After creating a schema, we can create a new table in the database.

Conclusion:

In this post, we learned to connect MySql with ASP.NET MVC.  Usually, developers combine SQL Server with ASP.NET MVC.  But considering we get MySQL for free, one might want to connect ASP.NET MVC with MySql.  Here we connect MySql with MVC and also learned how to use MySql workbench.  For more such post, please stay tuned to TecKangaroo.

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading…

0

Comments

0 comments