Extents
[This is prerelease documentation and is subject to change in future releases. Blank topics are included as placeholders.]

An extent is a field that defines storage. Extents can be derived from types or specified directly. All module-scoped extents cause SQL tables to be created when compiled. Extents that occur inside types cause SQL to be generated when an extent of the containing type is declared in a module.

There are a number of ways to create extents. A collection of entities is one of the commonest kinds of extents.

Any collection is an extent. This includes the following cases:

  • Collections of entity types, such as Employees : Employee*;.

  • Collections of directly specified entities.

  • Collection of simple (non-entity) types, such as ClaimIds : Integer32*;.

There are also ways to create non-collection extents. These include the following cases:

  • Derived from an entity type, such as Owner : Employee;.

  • Individual, simple, non-entity field, such as HomeSite : Text*;.

Collections of Entities

One of the commonest ways to create an extent is by defining a collection of entities. Often the entity is defined as a type, and a collection is created by referencing that type and appending the * operator. When you expect to reuse a data structure, define it as an entity type and reference that type when creating the extent.

In the following example, Employees is an extent defined as a collection of Employee types.

module Northwind {
    type Employee {
        LastName : Text;
        FirstName : Text; 
    }
    Employees : Employee*;
}

This code causes the following T-SQL code to be generated.

create table [Northwind].[Employees]
(
  [FirstName] nvarchar(max) not null,
  [LastName] nvarchar(max) not null
);

Extents without Types

Extents can also be defined without referencing a type. This is useful when a data structure is not expected to be reused. In this case the type of the extent is inferred, and is anonymous, without a name.

The following example defines the extent by directly specifying the items that it contains.

module Northwind {
    Addresses 
    { 
        {Id=1, Folder=1, State="NC", Zip=28173},
        {Id=2, Folder=1, State="WA", Zip=55555}
    };
}

This code causes the following T-SQL code to be generated. Note that because initial values are specified, T-SQL insert statements are generated.

create table [Northwind].[Addresses]
(
  [Folder] int not null,
  [Id] int not null,
  [State] nvarchar(max) not null,
  [Zip] int not null
);
go
insert into [Northwind].[Addresses] ([Id], [Folder], [State], [Zip])
 values (1, 1, N'NC', 28173)
;
insert into [Northwind].[Addresses] ([Id], [Folder], [State], [Zip])
 values (2, 1, N'WA', 55555)
;

Simple Field Extents

Extents can also be defined from simple types. In the following example, ItemCount is an extent.

module Northwind 
{
    ItemCount : Integer32;
}

This code causes the following T-SQL code to be generated.

create table [Northwind].[ItemCount]
(
  [Item] int not null
);
Fill out a survey about this topic for Microsoft.
Tags :


Page view tracker