Insert Update Delete(crud operations) in MVC 4 using Stored Procedure

Insert Update Delete(crud operations) in MVC 4 using Stored Procedure

In this tutorial i am going to explain about Insert Update Delete(crud operations) in MVC 4 using Stored Procedure. In my previous tutorial i have explained about CRUD operations using Entity Framework Database First Approach and MVC 4CRUD operations using Entity Framework Code First Approach and MVC 4ASP.NET MVC client side validation using data annotationsHow to create custom validation attribute in mvc 4 and Create primary key,composite key in Entity framework | Use of key attribute in ASP.Net MVC.

Implementation :

Now we will see the implementation of Insert Update Delete(crud operations) in MVC 4 using Stored Procedure.

Step 1:

Open your sql server and create table called Employee and create procedures for insert,update and delete. Below is the complete sql script.

Step 2:

Now create new mvc project in visual studio. For creating new project refer the below this link. Now right click on project select Add and ADO.Net Entity Model. And then choose EF Designer from database option for Choose model contents and then click Next. Refer below image for reference.

Step 1 of Insert Update Delete(crud operations) in MVC 4 using Stored Procedure

If the next dialog it will ask for connection details. Enter your connection string details and choose your database.

Step 2 of Insert Update Delete(crud operations) in MVC 4 using Stored Procedure

Test you connection and then proceed to next step. In the next step it will list down all the database objects such as tables, procedures and functions etc..

Step 3 of Insert Update Delete(crud operations) in MVC 4 using Stored Procedure

Choose your table, here Employee table i am choosing and then select procedures for insert,update and delete operations. And also check the Import selected stored procedures and functions into the entity model checkbox. Refer above image.

Step 3:

Now if you double click on the Employee.edmx file you can see the entity diagram of employee. Now right click on the diagram and choose Stored Procedure Mapping. 

Step 4 of Insert Update Delete(crud operations) in MVC 4 using Stored Procedure

It will give you the option to map Insert Update Delete(crud operations) procedures and we can map the output of procedures. Please refer below screenshot.

Step 5 of Insert Update Delete(crud operations) in MVC 4 using Stored Procedure

Now right click the controllers folder add a new controller with option MVC Controller with views, using Entity Framework. And then choose model and data context classes and then click ok. If you need step by step explanation on how to add controllers refer this link.

Output:

Now if you run the program you can see the output of how to do Insert Update Delete(crud operations) in MVC 4 using Stored Procedure.

Conclusion:

Hope you learned how to do Insert Update Delete(crud operations) in MVC 4 using Stored Procedure. Do you like this tutorial? Help us to improve. Please post your comments and feedback below.

Leave a Reply

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