MVC 5 CRUD Operation using Entity Framework 6

Till now, you have completed all the previous chapters. This is the time to combine all the work together and display output in a web browser. You are using Entity Framework so, you don't need to worry about writing SQL queries and connection for database operation. All database part will be handled by EF automatically.

There are 5 parts in this project and this is 5th Part.

Add a new Scaffolding Item to Controller

Step 1:

Right click on Controller folder. Select Add > New Scaffolded Item.

MVC 5 with Entity Framework 6

Step 2:

A window will open. Select MVC5 Controller with views, using Entity Framework and click on Add button.

MVC 5 with Entity Framework 6  

Step 3:

An Add Controller window will open. In Model class, select BookDetails (FirstEFProject.Models) and in the Data context class, select LibraryDBEntities (FirstEFProject.Models) and click on ADD button.

MVC 5 with Entity Framework 6

Step 4:

Now, see the Solution Explorer. You will notice that a BookDetailsController.cs is automatically added. You will also notice that BookDetails Views is also automatically added.

MVC 5 with Entity Framework 6

Step 5:

Set BookDetailsController to start page. Expand App_Start folder in solution explorer and open RouteConfig.cs.

App_Start Folder

Step 6:

Here change controller name Home to BookDetails

defaults: new { controller = "BookDetails", action = "Index", id = UrlParameter.Optional }

Step 7:

Press F5 to run your project.

EF - Database First Output

Output Picture

EF Output 1
EF Output 2
EF Output 3
EF Output 4
EF Output 5
EF Output 6


Till now, you learned how to create an MVC 5 Project with Entity Framework 6 with Database First. I hope you won’t get any trouble creating this project. If you have any trouble then you can post your problem in the comment section. In the next chapter, you will learn, Entity Framework 6 with Code First Approach.

More Articles


Share your thought


Please support us by enabling ads on this page. Refresh

But we have to show ads on our site to keep it free and updated. We have to pay huge server costs, domain costs, CDN Costs, Developer Costs, Electricity and Internet Bill. Your little contribution will encourage us to regularly update this site.