Saturday 25 March 2017

Insert, Update, Delete operation in MVC-4 with Entity Framework.

In This Session  I am going to describe Insert, Update, Delete operation in MVC-4 with Entity Framework.

Here I am using visual stdio 2012 (framework 4.5) , SQL server 2012 express and Entity Framework

So Lets start




Step -1

       Create 'Employee' Table in Database


Step -2

Open visual stdio 2012 and Create New Project. Select Asp.net MVC 4 web Application. Now Select Razor view and click OK Button.











































Step -3
Go to Solution Explorer and right click on Modal Folder and Add New item Select ADO.Net Entity Data Modal.


Step -4

Select EF Designer from database and click  on next button.




Step -5
Click on New Connection button if there is no already connection It will open Connection Windows




Step -6
Here just select Data Source,  SQL server name and database to want to connect . here my database is Demodatabase and table name is employee table  to connect and click on OK button




Step -6
Select Employee table checkbox and click on Next Button . you can change the modal namespace as your required 


Step -7

Here Entity framework create a  Employee table Modal  and its Generated all code and designer and connection string. Now just build the Application . 




Step-8
After successfully build the Application . Go to  solution Explorer and right click 
Controller folder 
and go to the Add New controller 





Step-9
Here I am going to create a 
Employee controller so
I put Employee as controller name and  in Template Select "MVC Controller with read write action and vies, using Framework" option and put the Data context class from drop down and select modal class from drop down. and click on add button.


Step-10
It Will automatically generate all the code for add , edit and delete Operation in Controller class. And It also generate view for Add ,Edit, Delete in View folder. Now Build the application And Run It.


Step-11
Before run the application just change the RouterConfig.cs Class, The Controller default name is 'Home' and you have to change it 'Employee'.because our controller name is 
Employee



Output will show like this


No comments:

Post a Comment

Thank you for comment