How to Scaffold a .NET 4.8 MVC Database first Web app with CRUD Controller and Views

Step-by-step guide

Click Create

Scaffold an Entity framework connection to your database

Step 1:

Under your src/WebAppliation folder create a new folder I will call this EFModels, we create the folder to help keep our project clean in addition using a seperate folder will make it simpler scaffold additional Entity framework connections should we need them.

Step 2: Create an Entity Framework model

Right click on the EFModels folder and Select Add, in the popup dialog, on the left choose Data, then in the right hand pane choose ADO.NET Entity Data Model, Give an appropriate name in Name input at the bottom of the dialog then click Add

The Entity Data Model Wizard dialog will appear,

choose EF Designer from database, click Next

For the "Data Connection" choose "New connection"

For the "Data Source" I chose Microsoft SQL Server (SqlClient)

For the "Server Name" enter the path to your SQL Server location, I entered ".\sqlexpress" but this could be a remote server such for example uk.sql10.yourservers.com,1486

Set your preferred Authentication, I chose "Windows Authentication", you may want to change to SQL Server Authentication in which case you will need a username/password

You may also need to set the checkbox "Trust Server Certificate"

Finally "Select or enter a database name", from the drop down list choose a database name

Click Ok

Now the Connection wizard has completed you will be back in the "Entity Data Model Wizard",

Enter the name you wish to use in Web.config as the connection string

Click Next 

Now you will need to choose which objects to include in your model. Expand the tables tree and choose the table(s) you require.

Adjust the default "Model Namespace" as required, I left it as WinnersAppDbModel

Click Finish

Heres my example WebApplication folder view after scaffolding the Entity FrameWork model

Scaffold an MVC Controller for one of your models

Now that we have an Entity framework model we can go ahead and scaffold an MVC controller and views for one of our models

Step 1: 

Right click on the Controller folder select Add | New Scaffolded item

Choose MVC Controller with views, using Entity Framework

Click Add

In the popup dialog choose the Model Class and the Data Context Class then adjust the Controller name input as required, 

Click Add

Once completed you will now have a new Controller in the Controllers folder and a corresponding set of (crud) views under the Views folder