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.
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:
Following the given steps will help us install the above software also.
- Search on the internet for MySql installer for Windows.
- Click on MySql Server links shown in the image.
- Now Click on MySql Community Server 5.7
- Scroll down until you find the link to download the MSI (Microsoft Installer). And click on that. The link says, 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.
- After downloading the installer. Double click on it and install it.
- Now click on agree and click on the Next button.
- 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.
- 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.
- Expand the node that says Connector/NET
- Click on the right arrow after selecting the latest version.
- Click on the Next on the bottom right.
- Now click on Execute.
- Choose Standalone MySql Server and click on Next.
- Click on Next
- Enter a new password and click on next.
- Now Click on Next.
- Click on Execute.
- Click on Finish.
- And click on Next.
- After successfully installing the above software. We will see the following software on the Programs and features as shown in the image.
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
- Select an empty project and check mark MVC and then click on ok
- 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.
- Select the following DLL and add it 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.
- Right click on the area shown in the image and select create schema.
- In the field shown in the image, enter the name for the new schema.
- Click on apply.
- Click on apply.
After creating a schema, we can create a new table in the database.
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.