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:Ã‚Â http://www.asp.net/mvc/
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:
- Right-click the App_Data folder in the Solution Explorer window and select the menu option Add, New Item.
- From the Add New Item dialog box, select SQL Server Database, give the database the name TrainingPortalDB.mdf, and click the Add button.
- Double-click the TrainingPortalDB.mdf file to open the Server Explorer/Database Explorer window.
- Click on the Database Diagrams folder and say yes to create a new diagram
- Setup your tables to look like this:
Create the Entity Framework Model
- Right-click the TrainingPortalMVC project.
- Select in the menu Add New Item
- Select from the Templates: ADO.NET Entity Data Model
- Enter the name TrainingPortalEDM.edmx then click Add
- Choose the Generate from database then click Next>
- For the data connection, select TrainingMvc.mdf make sure the checkbox is checked and the connection settings is TrainingMvcEntities then click Next>
- Check all tables in the database except for the sysdiagrams (dbo) one and make sure the Model Namespace is TrainingMvcModel.Ã‚Â Click Finish
- 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”
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.