[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.]
There are several different design patterns that specifically apply to SQL Server Modeling Services. To use these design patterns with your Microsoft code name “M” models, you must satisfy two requirements. First, some patterns require that the “M” code follow certain naming or structural conventions. Second, you must create a Post.sql file that calls Modeling Services stored procedures for applying each pattern.
The PatternApplication sample provides a convenient way to apply Modeling Services patterns to “M” models. It uses “M” to declaratively describe which patterns to apply. A Post.sql file is still required, but it simply calls the [Repository.Item].[ApplyStandardPatternsToModels] stored procedure.
Installing the PatternApplication Sample
Before you can use the PatternApplication sample, you must first install the sample into the target Modeling Services database. For more information, see How to: Install the PatternApplication Sample. This installs several tables in the Modeling Services database within the PatternApplication schema. It also installs the [Repository.Item].[ApplyStandardPatternsToModels] stored procedure.
Using PatternApplication Extents
The PatternApplication sample contains two extents: ModulePatternApplications and EntityPatternApplications. You create instances of the ModulePatternApplications extent to describe the Modeling Services patterns to apply to your “M” modules. You create instances of the EntityPatternApplications extent to describe the Modeling Services patterns to apply to your “M” extents. The following “M” code shows how to create these instances that specify the patterns to apply to a HumanResources module and its EmployeesTable extent.
module PatternApplication
{
import HumanResources;
ModulePatternApplications
{
HumanResources_Pattern
{
Module => about(HumanResources.EmployeesTable).Declaration.DefinedIn,
Pattern => { Patterns.AlterSchemaPermissions }
}
}
EntityPatternApplications
{
Employees_Pattern
{
Module => about(HumanResources.EmployeesTable).Declaration.DefinedIn,
Extent => about(HumanResources.EmployeesTable).Declaration,
Pattern =>
{
Patterns.CreateIdSequence,
Patterns.AddViewsInsteadOfTriggers,
Patterns.AddFolderForeignKey,
Patterns.AddAuditing,
Patterns.AddChangeTracking
}
}
}
}
In this example, the instance of the ModulePatternApplications extent applies Modeling Services patterns to the HumanResources module, and the instance of the EntityPatternApplications extent applies Modeling Services patterns to the EmployeesTable extent. Referencing the HumanResources module and its extents requires an import of the HumanResources module using the import keyword. The about keyword accesses both the module and the extent, so the “M” compiler can verify that the target module and extent exist, which eliminates errors related to misspellings. For both the ModulePatternApplications and EntityPatternApplications instances, the Pattern field specifies one or more Modeling Services patterns to apply to the respective module or extent.
The following sections provide more detail on using the ModulePatternApplications and EntityPatternApplications extents. For more information about specific Modeling Services patterns, see SQL Server Modeling Services Patterns.
The ModulePatternApplications Extent
The ModulePatternApplications extent contains the following fields.
| Field | Description |
|---|---|
Module |
The |
Pattern |
The |
The following table describes the possible module-specific values for the Pattern field.
| Value | Description |
|---|---|
Patterns.AlterSchemaPermissions |
The |
The EntityPatternApplications Extent
The EntityPatternApplications extent contains the following fields.
| Field | Description |
|---|---|
Module |
The |
Extent |
The |
Pattern |
The |
The following table describes the possible extent-specific values for the Pattern field.
| Value | Description |
|---|---|
Patterns.CreateIdSequence |
The |
Patterns.AddViewsInsteadOfTriggers |
The |
Patterns.AddFolderForeignKey |
The |
Patterns.AddAuditing |
The |
Patterns.AddChangeTracking |
The |
The Post.sql File
The PatternApplication extent instances describe the patterns that you want to apply. But you must call the [Repository.Item].[ApplyStandardPatternsToModels] stored procedure to apply those patterns. The easiest way to call this procedure is with a Post.sql file. A Post.sql file is a Transact-SQL script that you can add to your “M” project. After the “M” loader installs the models and instances in the database, it runs the Post.sql file. When using the PatternApplication sample, the Post.sql file always makes a single call to [Repository.Item].[ApplyStandardPatternsToModels].
execute [Repository.Item].[ApplyStandardPatternsToModels];
go
For a complete walkthrough of how to use the Post.sql file and other PatternApplication concepts, see Getting Started with the SQL Server Modeling CTP (SetupApplication Tutorial).