Entity Collection |
module M {
type Var {
i : Integer32;
j : Text => "initial value";
};
Vars : Var* {{ i => 10, j => "hi" },{ i => 1 }};
}
|
create table [M].[Vars]
(
[i] int not null,
[j] nvarchar(max) not null default N'initial value'
);
insert into [M].[Vars] ([i], [j])values (10, N'hi');insert into [M].[Vars] ([i])values (1);
|
Nested Entity Reference |
module M {
type Name {
Id : Integer32 => AutoNumber();
x : Integer32;
y : Text => "initial value";
} where identity(Id);
type Var {
i : Integer32;
name : Names;
};
Names : Name*;
Vars : Var* {{ i => 10, name => { x => 10 } },{ i => 1, name => { x => 20, y => "hi" } }};
}
|
create table [M].[Names]
(
[Id] int not null identity,
[x] int not null,
[y] nvarchar(max) not null default N'initial value',
constraint [PK_Names] primary key clustered ([Id])
);
create table [M].[Vars]
(
[name] int not null,
[i] int not null,
constraint [FK_Vars_name_M_Names] foreign key ([name]) references [M].[Names] ([Id])
);
insert into [M].[Names] ([x])values (10);declare @M_Names_Id0 bigint = @@identity;insert into [M].[Names] ([x], [y])values (20, N'hi');declare @M_Names_Id1 bigint = @@identity;insert into [M].[Vars] ([i], [name])values (10, @M_Names_Id0);insert into [M].[Vars] ([i], [name])values (1, @M_Names_Id1);
|
Nested Entity Collection Reference |
module M {
type Name {
Id : Integer32 => AutoNumber();
x : Integer32;
y : Text => "initial value";
} where identity(Id);
type Var {
Id : Integer32 => AutoNumber();
i : Integer32; names : Names*;
} where identity(Id);
Names : Name*;
Vars : Var* {{ i => 10, names => { { x => 10 }, { x => 100, y => "lo" } }},{ i => 1, names => { { x => 20, y => "hi" } }}};
}
|
create table [M].[Names]
(
[Id] int not null identity,
[x] int not null,
[y] nvarchar(max) not null default N'initial value',
constraint [PK_Names] primary key clustered ([Id])
);
create table [M].[Vars]
(
[Id] int not null identity,
[i] int not null,
constraint [PK_Vars] primary key clustered ([Id])
);
create table [M].[Vars_names]
(
[_Id] bigint not null identity,
[Vars_Id] int not null,
[Item] int not null,
constraint [PK_Vars_names] primary key clustered ([_Id]),
constraint [FK_Vars_names_Vars_Id_M_Vars] foreign key ([Vars_Id]) references [M].[Vars] ([Id]) on delete cascade,
constraint [FK_Vars_names_Item_M_Names] foreign key ([Item]) references [M].[Names] ([Id])
);
go
insert into [M].[Names] ([x])values (10);declare @M_Names_Id0 bigint = @@identity;insert into [M].[Names] ([x], [y])values (100, N'lo');declare @M_Names_Id1 bigint = @@identity;insert into [M].[Names] ([x], [y])values (20, N'hi');declare @M_Names_Id2 bigint = @@identity;insert into [M].[Vars] ([i])values (10);declare @M_Vars_Id0 bigint = @@identity;insert into [M].[Vars] ([i])values (1);declare @M_Vars_Id1 bigint = @@identity;insert into [M].[Vars_names] ([Item], [Vars_Id])values (@M_Names_Id0, @M_Vars_Id0);insert into [M].[Vars_names] ([Item], [Vars_Id])values (@M_Names_Id1, @M_Vars_Id0);insert into [M].[Vars_names] ([Item], [Vars_Id])values (@M_Names_Id2, @M_Vars_Id1);
|