Thanks
How to Add Update Delete using entity framework
Ask by Jonas Stuart
Updated 27 Mar 2017
I am providing you the solution of your question. Using entity framework and repository pattern
First create a demo database and create table RegistrationForm
And CountryList table and Insert record
Then create a new project and right click on model folder and select ado.net entity data model
And then And next and give sever and user name and password and select your database .Then your entity framework will be generated. It will look like this
For data annotation we have to add another class in model we cannot add data annotation in generated models class because when we update our entity framework our important validation will be loss to recover from this problem we will create meta class in the models folder.
And add following code
Meta classes contain all the validation attribute to associate this class to metadata add a class in the models folder and name it Partial
This is an interface so for implementation we will create a class in the models folder and will implement this interface into that
Now we will create unit of work for working with all the model classes.
Now add a home controller and inherit base controller in it. In the home controller I have create add, edit, delete and Update action
Our index view code in this I have added bootstrap library for better look and ajax validation
our partial view list code is
When we run our program it will look like this. From search text box we can filter our records.
When we click add then it will open in modal pop up it will look like this and it is from Add Partial View
And code for Add Partial
Thank you..