Part 4: Add Scaffolded Items and Run Project

You have created all the necessary files in previous parts. In this part we will add scaffolded item in controllers and Run our project.

Note: We divided this project into 4 Parts and this is the 4th PART

Parts of this Project

Add Scaffolded Item for CustomerProfile

1. Right click on Controllers folder Add New Scaffolded Item.

MVC 5 with Entity Framework 6

2. Select MVC 5 Controller with views, using Entity Framework. Click on Add button.

MVC 5 with Entity Framework 6

3. In the next window, select CustomerProfile (EFModelFirst) as Model class and CustomerModelContainer (EFModelFirst) as Data context class. Click on Add button.

AddController

Add Scaffolded Item for CustomerPurchase

1. Right click on Controllers folder Add New Scaffolded Item.

2. Select MVC 5 Controller with views, using Entity Framework. Click on Add button.

3. In the next window, select CustomerPurchase (EFModelFirst) as Model class and CustomerModelContainer (EFModelFirst) as Data context class. Click on Add button.

AddController

4. Now your Solution Explorer will look like this.

SolutionExplorer  

Adding Link on Navigation Menu

Now, add two link in navigation menu for CustomerProfile and CustomerPurchase and run your program.

1. Open Views Shared _Layout.cshtml

Layout

2. Add link like that.

<div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li>@Html.ActionLink("Home", "Index", "Home")</li>
                    <li>@Html.ActionLink("About", "About", "Home")</li>
                    <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
                    <li>@Html.ActionLink("Customer Profile", "Index", "CustomerProfiles")</li>
                    <li>@Html.ActionLink("Customer Purchase", "Index", "CustomerPurchases")</li>
                </ul>
            </div>

Run your Project

Press F5 to run your project.

Output Index Page
Create Page
Index Page
Index Page
Product Page
Index Page

Summary

In this tutorial, you learned Entity Framework Model First approach in details with complete programming example. I hope, you wouldn’t have any problem completing this project.

In the next section you will learn How to Manually Seed Data into Database using Code First.

 

Share your thought