How to: Use Type for Reuse
[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 tutorial is an introduction to using types in Microsoft code name “M”. It enables you to describe a basic type in “M”, incorporate it into a module, and compile it. In this tutorial, you create your “M” code using the code name “Intellipad” tool editor. You could also use the Visual Studio extensions for “M”, if you prefer.
To code the module
Open the “Intellipad” editor by clicking Start, All Programs, Microsoft Codename “Oslo” SDK, Tools, and Intellipad. The editor window appears.
Add the following code fragment.
module Northwind { }
To add a type, add the following code fragment inside the braces of the module statement.
type Address{ Street: Text where value.Count <128; City: Text; State: Text; ZipCode: Integer32; } where identity Street;
A
type
statement defines a data structure but does not cause any storage to be allocated. The identity keyword specifies which field within the type acts as a unique identifier for each instance of the type. Types that you want to use within other derived types require a unique identifier.Now add an extent that references this type.
Addresses: {Address*};
Add the following code fragment inside the braces of the module statement, following the
Address
type statement.type Employee{ Name: Text; MailingAddress: Address where value in Addresses; JobTitle: Text; } type Customer{ Name: Text; BillingAddress: Address where value in Addresses; }
To add extents for these types, add the following code fragment inside the braces of the module statement, following the
Addresses
extent statement.Employees : {Employee*}; Customers: {Customer*};
Example
The following is the complete “M” code sample for the Northwind
module.
module Northwind
{
type Address
{
Street: Text where value.Count <128;
City: Text;
State: Text;
ZipCode: Integer32;
} where identity Street;
type Employee
{
Name: Text;
MailingAddress: Address where value in Addresses;
JobTitle: Text;
}
type Customer
{
Name: Text;
BillingAddress: Address where value in Addresses;
}
Addresses: {Address*};
Employees : {Employee*};
Customers: {Customer*};
}