Insert, Update, Delete data in MVC5 using EntityFramework

This tutorial will show you how you can perform insert, update, delete operation in an mvc application using entity framework. This is called CRUD functionality. This you can use in MVC3, MVC4, MVC5.

Here we use entity framework 6 with MVC5.

First of here is our sql table:


DATABASE TABLE

So for this tutorial first we will create a new empty mvc application in this we will add a ADO.NET entity data model in Model.

NEW ITEM

Select EF Designer from database.

DATA MODEL

Then select Server name and Database name.

CONNECTION PROPERTIES

Select Yes radio button and click on Next.

ENTITY DATA MODEL WIZARD

Select Entity Framework 6.x.

ENTITY FRAMEWORK 6

Then Select table.

DATABASE


Now MVCdb.edmx add in Model folder.

EDMX FILE


Now Add Employee Controller.

CONTROLLER


Choose MVC5 Controller with views, using Entity Framework.

MVC 5 CONTROLLER

Select Model class and DataContextClass and give Controller name Employee.

ADD CONTROLLER


so now, automatically create  Index,Create,Delete,Edit,Details Views and Controller actions.

EMPLOYEE CONTROLLER

Now Run Application. (ctrl+F5)

RUN APPLICATION

Clcik on Create New.

CREATE
Add data and Click on Create button.

EMPLOYEE






1 comments:

Post a Comment