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
In Visual Studio 2010, on the File menu, select New, and then click Project.
In the New Project dialog, name the project HumanResources.
In the Installed Templates list, select Visual C#.
In the list of Visual C# templates, select Oslo Library. Click OK.
In Solution Explorer, rename the Model.m file to Employees.m.
Replace the code in the Employees.m file with the following simplified HumanResources model. This code defines a module named
HumanResoures
. TheHumanResources
module only defines a simplifiedEmployees
extent. For more information about modules and extents in “M”, see "M" Basics.module HumanResources { import System; Employees : {( HasFolderAndAutoId & { Name : Text; } )*}; }
Note
The HasFolderAndAutoId type is defined in the imported System module. It creates an additional auto-incrementing
Id
field as well as aFolder
field that references the Repository.Item::FoldersTable extent. For more information, see Adding Folders (Modeling Services).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.
Click the Browse tab.
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.
On the Build menu, click Build Solution.
To load the HumanResources model into the Modeling Services database
In Solution Explorer, right-click the HumanResources project, and then click Properties.
In the project properties window, select the M Deployment section.
Click the ellipsis button next to the Database Connection String edit box.
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).
In the database section, type the name of the default Modeling Services database, Repository.
Click OK.
In Solution Explorer, right-click the HumanResources project, and then click Deploy.
On the View menu, click Output.
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.
Note
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.
On the Start Menu, click All Programs, Microsoft SQL Server Modeling CTP, and open the Microsoft SQL Server Modeling CTP Command Prompt.
At the command prompt, type
sqlcmd.exe
and press ENTER.sqlcmd.exe
Type the following lines, pressing ENTER between each line.
use Repository go exec [Repository.Item].[AddFolderForeignKey] @schema='HumanResources', @baseName='Employees', @folderColumn='Folder' go
Type
quit
to exit.
See Also
Concepts
Designing Models and Domains using "M"