Using Extents to Define Entities
[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.]
After deciding on one or more modules for your domain, you can model specific entities within those modules by defining Microsoft code name “M” extents.
Defining Extents
An extent is a location to store data. This differentiates extents from other “M” constructs that describe data without implying storage. In most cases, extents are defined with one or more fields that determine the kinds of data that can be stored in the extent.
To understand extents, consider the example of the Contact
domain. To model this domain, you must describe categories of data, such as phone information. The following “M” code defines a PhoneNumbers
extent.
module Contact
{
PhoneNumbers :
{(
{
Work : Text;
Home : Text?;
Mobile : Text?;
}
)*};
}
Tip
The Contact
module is also shown here for clarity. For more information about creating modules, see Using Modules to Scope the Model.
In this example, the PhoneNumbers
extent has three text fields: Work
, Home
, and Mobile
. These fields represent the different types of phone numbers for a contact. The Home
and Mobile
fields are optional, which is indicated by the question mark that follows their type.
For more information about extents, see "M" Types Overview.
Adding Initial Values to Extents
You can use “M” to define initial values for the extent. In database terms, initial values are analogous to new rows in a table. “M” refers to these new extent instances as initial values, because in the typical case, the extent instances that you add in “M” code will only be the initial records in the extent. Future records will be added either programmatically or through a tool like Microsoft code name “Quadrant”.
There are a few ways to define initial values. The following example shows how to create two extent instances immediately following the extent definition.
PhoneNumbers :
{(
{
Work : Text;
Home : Text?;
Mobile : Text?;
}
)*}
{
{ Work => "555-555-5555", Home => "555-555-5555", Mobile => "555-555-5555" },
{ Work => "555-555-5555", Mobile => "555-555-5555" }
}
In this example two instances are added to the PhoneNumbers
extent. The second instance does not assign a value to the Home
field, which is allowed because that is one of the optional fields.
You can also create initial values in a separate code block that is prefixed with the extent name. This code block can even reside in a different “M” source file. The following example uses two Contact
module declarations. The first Contact
module defines the PhoneNumbers
extent. The second Contact
module defines two instances for the PhoneNumbers
extent.
module Contact
{
PhoneNumbers :
{(
{
Work : Text;
Home : Text?;
Mobile : Text?;
}
)*};
}
module Contact
{
PhoneNumbers
{
{ Work => "555-555-5555", Home => "555-555-5555", Mobile => "555-555-5555" },
{ Work => "555-555-5555", Mobile => "555-555-5555" }
}
}
Note
Note that this code example is equivalent to the previous example that defined the initial values immediately following the extent. This just shows another way to add initial values to an extent in “M”.