Compartir a través de


Anonymous Collections (M to SQL Mapping)

[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.]

Microsoft code name “M” supports the creation of anonymous collections in an expression (such as {1, 2, 4, 8, 16 }). This is supported using queries and union all so that the collections can be returned from views and used anywhere expressions can be used.

Type “M” Example SQL Example

Scalar collection

module M {
    Thirty : Integer32 => 30;
    V() { { 1, 10, 3, Thirty, 2, 20, 20 } }
}
create table [M].[Thirty]
(
  [Item] int not null
);
create view [M].[V]
as
    select 1 as [Item]union allselect 10 as [Item]union allselect 3 as [Item]union allselect [Item] as [Item]from [M].[Thirty]union allselect 2 as [Item]union allselect 20 as [Item]union allselect 20 as [Item];

Entity collection

module M
{
    SingleA : {
        i : Integer32;
        j : Text;
    } { i => 100, j => "hundred" };
    V() {
      {{ i => 20, j => "twenty" },SingleA,{ i => 10, j => "ten" },{ i => 20, j => "twenty" }}
    }
}
create table [M].[SingleA]
(
  [i] int not null,
  [j] nvarchar(max) not null
);
 
insert into [M].[SingleA] ([i], [j])
 values (100, N'hundred');
create view [M].[V]
as
    select 20 as [i], N'twenty' as [j]union allselect [i] as [i], [j] as [j]from [M].[SingleA]union allselect 10 as [i], N'ten' as [j]union allselect 20 as [i], N'twenty' as [j];

Empty collection

module M
{
    V() : Integer32* { { } }
}
create view [M].[V]
as
  select 1where 1 = 0;

“M”->SQL does not yet support anonymous collections with entities of different types (different sets of columns) or collections of collections.