How to: Install the HumanResources Sample Model using Visual Studio

[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]

This topic creates a simple HumanResources model in Microsoft code name “M” and then installs this model into the SQL Server Modeling Services database. This HumanResources model is targeted by each of the tutorials in this section. These topics show various techniques for creating, reading, updating, and deleting model instance data.

Note that this model uses the Modeling Services Folder pattern. The Employees extent contains a Folder field that references the Repository.Item::FoldersTable extent. Folders logically contain items; they also provide access to security and management benefits in the SQL Server Modeling Services database. For more information about Folders, see Using Folders and Ids.

In this tutorial, you will perform the following tasks:

  • Use Visual Studio 2010 to create a simple HumanResources model in “M”.

  • Deploy the model to the Modeling Services database.

To create an "M" model of an Employees entity

  1. In Visual Studio 2010, on the File menu, select New, and then click Project.

  2. In the New Project dialog, name the project HumanResources.

  3. In the Installed Templates list, select Visual C#.

  4. In the list of Visual C# templates, select Oslo Library. Click OK.

  5. In Solution Explorer, rename the Model.m file to Employees.m.

  6. Replace the code in the Employees.m file with the following simplified HumanResources model. This code defines a module named HumanResoures. The HumanResources module only defines a simplified Employees extent. For more information about modules and extents in “M”, see "M" Basics.

    module HumanResources
        import System;
        Employees :
            HasFolderAndAutoId &
                Name : Text;


    The HasFolderAndAutoId type is defined in the imported System module. It creates an additional auto-incrementing Id field as well as a Folder field that references the Repository.Item::FoldersTable extent. For more information, see Adding Folders (Modeling Services).

  7. To use the HasFolderAndAutoId type, add a reference to the Repository.dll assembly. In Solution Explorer, right-click the References node, and then click Add Reference.

  8. Click the Browse tab.

  9. Navigate to the bin directory of the SQL Server Modeling CTP and select the Repository.dll file. By default, this is located at C:\Program Files\Microsoft Oslo\1.0\bin\Repository.dll.

  10. On the Build menu, click Build Solution.

To load the HumanResources model into the Modeling Services database

  1. In Solution Explorer, right-click the HumanResources project, and then click Properties.

  2. In the project properties window, select the M Deployment section.

  3. Click the ellipsis button next to the Database Connection String edit box.

  4. In the Connection Properties dialog, enter the name of the target instance of SQL Server. For the default instance on the current machine, specify (local).

  5. In the database section, type the name of the default Modeling Services database, Repository.

  6. Click OK.

  7. In Solution Explorer, right-click the HumanResources project, and then click Deploy.

  8. On the View menu, click Output.

  9. The output window should indicate a successful build and deployment.

To apply the Modeling Services Folder pattern

In the previous steps, the HasFolderAndAutoId type added a Folder field to the Employees extent. However, an additional stored procedure call is required to fully apply the Modeling Services Folder pattern. The [Repository.Item].[AddFolderForeignKey] stored procedure adds a relationship from the Folder column of the Employees extent to the Id column of the Repository.Item::FoldersTable extent. It also sets a property on this relationship to ensure that when the referenced Folder is deleted, any data in the Employees table that uses that Folder is deleted.


To save time, the following task calls this procedure directly from a SqlCmd.exe command prompt. However, this pattern and other patterns can be applied more systematically and accurately with the PatternApplication sample. For more information, see Using the PatternApplication Sample.

  1. On the Start Menu, click All Programs, Microsoft SQL Server Modeling CTP, and open the Microsoft SQL Server Modeling CTP Command Prompt.

  2. At the command prompt, type sqlcmd.exe and press ENTER.

  3. Type the following lines, pressing ENTER between each line.

    use Repository
    exec [Repository.Item].[AddFolderForeignKey] @schema='HumanResources', @baseName='Employees', @folderColumn='Folder'
  4. Type quit to exit.

See Also


Designing Models and Domains using "M"

Other Resources

Loading Domain Models with Data