type ("M" Technical Reference)
[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.]
Type is a fundamental concept of the Microsoft code name “M” language. It specifies a schema or pattern that values that belong to that type must conform to. The type keyword is used to define a named, reusable type.
There are three kinds of types that can be created, each with its own syntax.
Entity types
Collection types
Constrained types
Entity Types
An entity type specifies multiple fields, which can each be of different types, as part of the entity type.
Entity Type Syntax
The following syntax shows how to create an entity type.
type TypeName { 1 or more field definitions }
TypeName is the name of the new type.
Inside the braces are field definitions, each terminated by a ;.
Creating an Entity Type
The following code creates a person
entity.
type person
{
name: Text;
address: Text;
}
Collection Types
A collection type contains multiple occurrences of an element.
Collection Type Syntax
The following syntax shows how to create a collection type by explicitly listing its members.
type TypeName { value1, …. , valueN };
TypeName is the name of the new type.
Inside the braces are the values that make up the collection, separated by commas.
Creating a Collection Type by Explicit Specification
The following example creates a collection type by explicitly listing the members of the type. This method is often used when specifying enumerations.
type People {“customer”, “supplier”, “employee”};
Constrained Types
A constrained type is a type derived from an existing type by applying a constraint.
Constrained Type Syntax
The following syntax shows how to create a derived type from an existing type, with an optional constraint being added.
type DerivedTypeName : ExistingTypeName constraint
DerivedTypeName is the name of the new type.
ExistingTypeName is the name of the existing type.
constraint is the constraint expression applied to the existing type.
Creating a Constrained Type from an Existing Type
The following example creates a derived type from an existing type by adding a constraint.
module Contacts
{
type person
{
name: Text;
address : Text;
balance : Integer32;
}
type OverdrawnCustomer : person where value.balance > 10000;
}