MVC and Table Inheritance: Part 1

PART 1:  Setting up the database and Entity Framework Model

Okay, so say you need to create an internal IIS hosted web application that acts as a portal for managing internal training courses.  You could do a simple ASP.NET web forms app…. but what’s the fun in that?!?  Besides, you know that you’re going to need to expand this thing regularly to handle different course types and provide different layers of permission depending on the user.  Well, as it happens, ASP.NET MVC is a really nice way to address such a situation (especially if you’re already familiar with using Java and Struts).

Before we get started you’ll need to get the usual downloads from Microsoft found here:

Create ASP.NET MVC Project

Then you’ll need to open either Visual Studio 2008 or the free Visual Web Developer 2008 Express and select the File->New Project menu item.  This will bring up the “New Project” dialog.  To create a new ASP.NET MVC application, we’ll select the “Web” node on the left-hand side of the dialog and then choose the ASP.NET MVC Web Application template and enter the following:

  • Name: TrainingPortalMVC
  • Location: C:\Development
  • Solution: Create new Solution
  • Solution Name: TrainingPortalMVC
  • Create directory for solution:  checked

SQL 2005 Database Tables

To setup your MVC project so it can use the Microsoft Entity Framework:

  1. Right-click the App_Data folder in the Solution Explorer window and select the menu option Add, New Item.
  2. From the Add New Item dialog box, select SQL Server Database, give the database the name TrainingPortalDB.mdf, and click the Add button.
  3. Double-click the TrainingPortalDB.mdf file to open the Server Explorer/Database Explorer window.
  4. Click on the Database Diagrams folder and say yes to create a new diagram
  5. Setup your tables to look like this:

Create the Entity Framework Model


  1. Right-click the TrainingPortalMVC project.
  2. Select in the menu Add New Item
  3. Select from the Templates: ADO.NET Entity Data Model
  4. Enter the name TrainingPortalEDM.edmx then click Add
  5. Choose the Generate from database then click Next>
  6. For the data connection, select TrainingMvc.mdf make sure the checkbox is checked and the connection settings is TrainingMvcEntities then click Next>
  7. Check all tables in the database except for the sysdiagrams (dbo) one and make sure the Model Namespace is TrainingMvcModel.  Click Finish

Suggested Modifications

  • Open the ModelBrowser panel in Visual Studio 2008, and expand the EntityContainer->EntitySets and add “Set” to the end of your Entity Sets….. Trust me, it will make things much less confusing later…

When you’re done you should have something like this:

This is the end of Part 1…… Calm down, I know you can’t possibly wait for more answers, but a girl’s gotta have a little mystery to keep things interesting.  Good luck and hopefully this will help you shed another angle of light to get a better idea of how you want to approach this type of application until I can finish procrastinating…. I mean preparing Part 2…..

One thought on “MVC and Table Inheritance: Part 1”

  1. ok lets see what will u do next, i mean all staff like many-to-many in your views with checkboxlist and cascade deletes

    until now everyone knows how drag and drop objects, show us continue

    ps. subscribed for this series

Comments are closed.