CRUD in Asp.net MVC
In this article I will explain how we can make CRUD operations in ASP.Net MVC. In this article we will use a data base first
approach and perform CRUD operations using entity framework. I hope you like this article and get some information from it.
Open Visual Studio. Here I use Visual Studio 2019, you can use any one as your system.
Create a new project by clicking on File>New>Project.
Select Asp.Net Web Application and click on next button.
In the next screen you need to enter a few details like your project name, project location where you want to save your project,
solution name and .Net Framework version. After entering all details click on Create button.
In Next select MVC project and click on Create button. Now your project is ready and you can see project structure in below image. Here I deleted all view from home controller because we created a new for our requirement.
Now in this project we will use database first approach so we need to create a database and a table. Here I created a database name with Tutorials and table Employee with the following columns as you can see in the below image.
Now we need to add Entity Framework in our project for performing some operation. For adding Entity Framework click on project name in solution explore then click on Manage NuGet Packages.
Now you see a window with many NuGet Packages. Search for Entity framework and click on install button and after a few seconds Entity Framework is installed in your project.
Now we need to add ADO.Net Entity Data Model in our project. For adding ADO.Net Entity Data Model click on your project name then click on Add and then click on new Item or you can use short cut key Ctrl+Shift+A .
Now you see a popup window. Select ADO.Net Entity Data Model, give appropriate name and click on add button.
There is a change that in visual studio 2019 you cannot see ADO.Net Entity Data Model option. For adding ADO.Net Entity Data Model in visual studio open visual studio install , select modify option by clicking on more button. Now you see a new window click on Individual Component tab, search for Entity Framework tool then select it and click on modify button.
After adding ADO.Net Entity Data Model you will see a popup window. Select EF Designer From database and click on next button.
Now select your database from drop down and give connection string name, and click on Next button.
Select tables which you want to add in project, here I have only one table so I select that, gave Model Namespace name and Click on finish button.