The Model contains all of the database access, business, and validation logic. In this example, we'll generate an ADO.NET Entity Data Model (.edmx), from the view stored in the NorthWND.MDF database.
|
Note: This step assumes that you have created a MVC Tools project. If you haven’t, see the Creating an MVC Tools Project topic. It also assumes that you have added the NORTHWND.MDF database installed with the product to the project's App_Data folder. The NORTHWND.MDF file can be found in the Studio for ASP.NET Wijmo\ASP.NET MVC Tools\CS\WijmoMVC\WijmoMVC\App_Data folder within C:\Users\<username>\Documents\ComponentOne Samples (Windows 7/Vista) or C:\Documents and Settings\<username>\My Documents\ComponentOne Samples (Windows XP). |
- Complete the following steps:.In the Solution Explorer, right click App_Data and select Add | Existing Item. Select NORTHWND.MDF in the App_Data folder and click Add.
- Right-click the Models folder and select Add | New Item.
- In the Add New Item dialog box, choose Data under Visual C#.
- Select ADO.NET Entity Data Model, enter a name, such as MyNorthWindEDM, in the Name field, and click Add. The Entity Data Model Wizard appears.
- Select Generate from database and click Next.
- In the Choose Your Data Connection dialog box, click New Connection. The Choose Data Source dialog box appears.
- Select Microsoft SQL Server Database File and click Continue.
- Browse to find the NORTHWND.MDF file in the project’s App_Data folder and click Open.
- You can test the connection and click OK.
- You can leave Save Entity Settings in Web.Config as NORTHWNDEntities checked and click Next.
- In the Choose Your Database Objects window, expand the Tables node, select the Products and Categories check boxes and click Finish.
The model, in this case MyNorthWindEDM.edmx, is created and added to the Models folder of the project.
In the next step, wijmenu Step 2 of 3: Creating the Controller, we’ll create a controller, which will handle the user action by returning a view that contains the data from the model.