Repository navigation
code generation conventions
In order to translate a UML model to code we make use of the following conventions for reference properties, i.e. Associations and Composite Aggregation. The assumption we make is that each class has a property that is its unique identifier, the unique identifier is used as reference pointer for DTO and SQL foreign key constraint generation. We typically make use of Guid or UUID for the unique identifier.
| ID | Reference Property |
|---|---|
| A001 | A [0..1] --> [0..1] B |
| A002 | A [0..1] --> [1..1] B |
| A003 | A [0..1] --> [0..*] B |
| A004 | A [0..1] --> [1..*] B |
| A005 | A [0..1] --> [n..*] B |
| A006 | A [1..1] --> [0..1] B |
| A007 | A [1..1] --> [1..1] B |
| A008 | A [1..1] --> [0..*] B |
| A009 | A [1..1] --> [1..*] B |
| A010 | A [1..1] --> [n..*] B |
| A011 | A [0..*] --> [0..1] B |
| A012 | A [0..*] --> [1..1] B |
| A013 | A [0..] --> [0..] B |
| A014 | A [0..] --> [1..] B |
| A015 | A [0..] --> [n..] B |
| A016 | A [1..*] --> [0..1] B |
| A017 | A [1..*] --> [1..1] B |
| A018 | A [1..] --> [0..] B |
| A019 | A [1..] --> [1..] B |
| A020 | A [1..] --> [n..] B |
| A021 | A [n..*] --> [0..1] B |
| A022 | A [n..*] --> [1..1] B |
| A023 | A [n..] --> [0..] B |
| A024 | A [n..] --> [1..] B |
| A025 | A [n..] --> [n..] B |
| A026 | A [1..1] ◆--> [0..1] B |
| A027 | A [1..1] ◆--> [1..1] B |
| A028 | A [1..1] ◆--> [0..*] B |
| A029 | A [1..1] ◆--> [1..*] B |
| A030 | A [1..1] ◆--> [n..*] B |
Each pattern is drawn as an association from A to B, with the multiplicity and the name of the property at each end. prop_b is the property of A that refers to B; prop_a is the opposite end.
-
nstands for a lower bound that is greater than 1. -
◆marks composite aggregation:AcontainsB.
Whether a foreign key cascades an update or a delete follows from what the row means:
- The foreign key of a contained element to its container cascades (
ON UPDATE CASCADE ON DELETE CASCADE). A contained element cannot exist without its container, so it is deleted with it. This applies to the composite patterns A026 to A030. - Both foreign keys of a junction table cascade. A row in a junction table is a link between two elements and has no meaning when either of them is gone.
- The foreign key of a plain association does not cascade. The referenced element is not owned, so deleting it while it is still referenced is an error that the constraint reports.
A [0..1] --> [0..1] B
_ _ _ _ _ _ _ _
| | [0..1] [0..1] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A.prop_b
public class A {
/// <summary>
/// Gets or sets the (nullable) unique identifier of <see cref="B"/>
/// </summary>
public Guid? Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the (nullable) reference to <see cref="B"/>
/// </summary>
public B? Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY,
b_id UUID
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
ALTER TABLE "A" ADD CONSTRAINT fk_b FOREIGN KEY (b_id) REFERENCES "B"("id") DEFERRABLE;
A [0..1] --> [1..1] B
_ _ _ _ _ _ _ _
| | [0..1] [1..1] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A.prop_b -> Because of possibility of referential integrity check
public class A {
/// <summary>
/// Gets or sets the unique identifier of <see cref="B"/>
/// </summary>
public Guid Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the reference to <see cref="B"/>
/// </summary>
public B Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY,
b_id UUID NOT NULL
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
ALTER TABLE "A" ADD CONSTRAINT fk_b FOREIGN KEY (b_id) REFERENCES "B"("id") DEFERRABLE;
A [0..1] --> [0..*] B
_ _ _ _ _ _ _ _
| | [0..1] [0..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: B.prop_a
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY,
a_id UUID
)
ALTER TABLE "B" ADD CONSTRAINT fk_a FOREIGN KEY (a_id) REFERENCES "A"("id") DEFERRABLE;
A [0..1] --> [1..*] B
_ _ _ _ _ _ _ _
| | [0..1] [1..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: B.prop_a
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY,
a_id UUID
)
ALTER TABLE "B" ADD CONSTRAINT fk_a FOREIGN KEY (a_id) REFERENCES "A"("id") DEFERRABLE;
A [0..1] --> [n..*] B
_ _ _ _ _ _ _ _
| | [0..1] [n..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: B.prop_a
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY,
a_id UUID
)
ALTER TABLE "B" ADD CONSTRAINT fk_a FOREIGN KEY (a_id) REFERENCES "A"("id") DEFERRABLE;
A [1..1] --> [0..1] B
_ _ _ _ _ _ _ _
| | [1..1] [0..1] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: B.prop_a
public class A {
/// <summary>
/// Gets or sets the (nullable) unique identifier of <see cref="B"/>
/// </summary>
public Guid? Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the (nullable) reference to <see cref="B"/>
/// </summary>
public B? Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY,
a_id UUID NOT NULL
)
ALTER TABLE "B" ADD CONSTRAINT fk_a FOREIGN KEY (a_id) REFERENCES "A"("id") DEFERRABLE;
A [1..1] --> [1..1] B
_ _ _ _ _ _ _ _
| | [1..1] [1..1] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: B.prop_a
public class A {
/// <summary>
/// Gets or sets the unique identifier of <see cref="B"/>
/// </summary>
public Guid Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the reference to <see cref="B"/>
/// </summary>
public B Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY,
a_id UUID NOT NULL
)
ALTER TABLE "B" ADD CONSTRAINT fk_a FOREIGN KEY (a_id) REFERENCES "A"("id") DEFERRABLE;
A [1..1] --> [0..*] B
_ _ _ _ _ _ _ _
| | [1..1] [0..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: B.prop_a
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY,
a_id UUID NOT NULL
)
ALTER TABLE "B" ADD CONSTRAINT fk_a FOREIGN KEY (a_id) REFERENCES "A"("id") DEFERRABLE;
A [1..1] --> [1..*] B
_ _ _ _ _ _ _ _
| | [1..1] [1..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: B.prop_a
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY,
a_id UUID NOT NULL
)
ALTER TABLE "B" ADD CONSTRAINT fk_a FOREIGN KEY (a_id) REFERENCES "A"("id") DEFERRABLE;
A [1..1] --> [n..*] B
_ _ _ _ _ _ _ _
| | [1..1] [n..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: B.prop_a
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY,
a_id UUID NOT NULL
)
ALTER TABLE "B" ADD CONSTRAINT fk_a FOREIGN KEY (a_id) REFERENCES "A"("id") DEFERRABLE;
A [0..*] --> [0..1] B
_ _ _ _ _ _ _ _
| | [0..*] [0..1] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A.prop_b -> Because of cardinality switch
public class A {
/// <summary>
/// Gets or sets the (nullable) unique identifier of <see cref="B"/>
/// </summary>
public Guid? Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the (nullable) reference to <see cref="B"/>
/// </summary>
public B? Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY,
b_id UUID
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
ALTER TABLE "A" ADD CONSTRAINT fk_b FOREIGN KEY (b_id) REFERENCES "B"("id") DEFERRABLE;
A [0..*] --> [1..1] B
_ _ _ _ _ _ _ _
| | [0..*] [1..1] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A.prop_b -> Because of cardinality switch
public class A {
/// <summary>
/// Gets or sets the unique identifier of <see cref="B"/>
/// </summary>
public Guid Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the reference to <see cref="B"/>
/// </summary>
public B Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY,
b_id UUID NOT NULL
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
ALTER TABLE "A" ADD CONSTRAINT fk_b FOREIGN KEY (b_id) REFERENCES "B"("id") DEFERRABLE;
A [0..*] --> [0..*] B
_ _ _ _ _ _ _ _
| | [0..*] [0..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A_prop_b__B -> Junction Table
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
CREATE TABLE "A_b_id__B"
(
"sourceA" UUID NOT NULL,
"targetB" UUID NOT NULL,
PRIMARY KEY ("sourceA", "targetB")
)
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "A_FK_Source" FOREIGN KEY ("sourceA") REFERENCES "A" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "B_FK_Target" FOREIGN KEY ("targetB") REFERENCES "B" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
A [0..*] --> [1..*] B
_ _ _ _ _ _ _ _
| | [0..*] [1..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A_prop_b__B -> Junction Table
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
CREATE TABLE "A_b_id__B"
(
"sourceA" UUID NOT NULL,
"targetB" UUID NOT NULL,
PRIMARY KEY ("sourceA", "targetB")
)
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "A_FK_Source" FOREIGN KEY ("sourceA") REFERENCES "A" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "B_FK_Target" FOREIGN KEY ("targetB") REFERENCES "B" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
A [0..*] --> [n..*] B
_ _ _ _ _ _ _ _
| | [0..*] [n..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A_prop_b__B -> Junction Table
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
CREATE TABLE "A_b_id__B"
(
"sourceA" UUID NOT NULL,
"targetB" UUID NOT NULL,
PRIMARY KEY ("sourceA", "targetB")
)
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "A_FK_Source" FOREIGN KEY ("sourceA") REFERENCES "A" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "B_FK_Target" FOREIGN KEY ("targetB") REFERENCES "B" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
A [1..*] --> [0..1] B
_ _ _ _ _ _ _ _
| | [1..*] [0..1] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A.prop_b -> Because of cardinality switch
public class A {
/// <summary>
/// Gets or sets the (nullable) unique identifier of <see cref="B"/>
/// </summary>
public Guid? Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the (nullable) reference to <see cref="B"/>
/// </summary>
public B? Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY,
b_id UUID
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
ALTER TABLE "A" ADD CONSTRAINT fk_b FOREIGN KEY (b_id) REFERENCES "B"("id") DEFERRABLE;
A [1..*] --> [1..1] B
_ _ _ _ _ _ _ _
| | [1..*] [1..1] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A.prop_b -> Because of cardinality switch
public class A {
/// <summary>
/// Gets or sets the unique identifier of <see cref="B"/>
/// </summary>
public Guid Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the reference to <see cref="B"/>
/// </summary>
public B Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY,
b_id UUID NOT NULL
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
ALTER TABLE "A" ADD CONSTRAINT fk_b FOREIGN KEY (b_id) REFERENCES "B"("id") DEFERRABLE;
A [1..*] --> [0..*] B
_ _ _ _ _ _ _ _
| | [1..*] [0..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A_prop_b__B -> Junction Table
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
CREATE TABLE "A_b_id__B"
(
"sourceA" UUID NOT NULL,
"targetB" UUID NOT NULL,
PRIMARY KEY ("sourceA", "targetB")
)
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "A_FK_Source" FOREIGN KEY ("sourceA") REFERENCES "A" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "B_FK_Target" FOREIGN KEY ("targetB") REFERENCES "B" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
A [1..*] --> [1..*] B
_ _ _ _ _ _ _ _
| | [1..*] [1..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A_prop_b__B -> Junction Table
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
CREATE TABLE "A_b_id__B"
(
"sourceA" UUID NOT NULL,
"targetB" UUID NOT NULL,
PRIMARY KEY ("sourceA", "targetB")
)
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "A_FK_Source" FOREIGN KEY ("sourceA") REFERENCES "A" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "B_FK_Target" FOREIGN KEY ("targetB") REFERENCES "B" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
A [1..*] --> [n..*] B
_ _ _ _ _ _ _ _
| | [1..*] [n..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A_prop_b__B -> Junction Table
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
CREATE TABLE "A_b_id__B"
(
"sourceA" UUID NOT NULL,
"targetB" UUID NOT NULL,
PRIMARY KEY ("sourceA", "targetB")
)
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "A_FK_Source" FOREIGN KEY ("sourceA") REFERENCES "A" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "B_FK_Target" FOREIGN KEY ("targetB") REFERENCES "B" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
A [n..*] --> [0..1] B
_ _ _ _ _ _ _ _
| | [n..*] [0..1] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A.prop_b -> because of single reference value on A side
public class A {
/// <summary>
/// Gets or sets the (nullable) unique identifier of <see cref="B"/>
/// </summary>
public Guid? Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the (nullable) reference to <see cref="B"/>
/// </summary>
public B? Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY,
b_id UUID
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
ALTER TABLE "A" ADD CONSTRAINT fk_b FOREIGN KEY (b_id) REFERENCES "B"("id") DEFERRABLE;
A [n..*] --> [1..1] B
_ _ _ _ _ _ _ _
| | [n..*] [1..1] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A.prop_b -> because of single reference value on A side
public class A {
/// <summary>
/// Gets or sets the unique identifier of <see cref="B"/>
/// </summary>
public Guid Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the reference to <see cref="B"/>
/// </summary>
public B Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY,
b_id UUID NOT NULL
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
ALTER TABLE "A" ADD CONSTRAINT fk_b FOREIGN KEY (b_id) REFERENCES "B"("id") DEFERRABLE;
A [n..*] --> [0..*] B
_ _ _ _ _ _ _ _
| | [n..*] [0..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A_prop_b__B -> Junction Table
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
CREATE TABLE "A_b_id__B"
(
"sourceA" UUID NOT NULL,
"targetB" UUID NOT NULL,
PRIMARY KEY ("sourceA", "targetB")
)
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "A_FK_Source" FOREIGN KEY ("sourceA") REFERENCES "A" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "B_FK_Target" FOREIGN KEY ("targetB") REFERENCES "B" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
A [n..*] --> [1..*] B
_ _ _ _ _ _ _ _
| | [n..*] [1..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A_prop_b__B -> Junction Table
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
CREATE TABLE "A_b_id__B"
(
"sourceA" UUID NOT NULL,
"targetB" UUID NOT NULL,
PRIMARY KEY ("sourceA", "targetB")
)
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "A_FK_Source" FOREIGN KEY ("sourceA") REFERENCES "A" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "B_FK_Target" FOREIGN KEY ("targetB") REFERENCES "B" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
A [n..*] --> [n..*] B
_ _ _ _ _ _ _ _
| | [n..*] [n..*] | |
| A |------------------->| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
POCO: A.prop_b
SQL: A_prop_b__B -> Junction Table
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// </summary>
public List<Guid> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
public class A {
/// <summary>
/// Gets or sets the list of references to <see cref="B"/>
/// </summary>
public List<B> Prop_b { get; set; }
}
public class B {
// B does not know of A
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY
)
CREATE TABLE "A_b_id__B"
(
"sourceA" UUID NOT NULL,
"targetB" UUID NOT NULL,
PRIMARY KEY ("sourceA", "targetB")
)
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "A_FK_Source" FOREIGN KEY ("sourceA") REFERENCES "A" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
ALTER TABLE "A_b_id__B" ADD CONSTRAINT "B_FK_Target" FOREIGN KEY ("targetB") REFERENCES "B" ("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
Important
Please note that for composite aggregation on the owner side we only support [1..1] as other multiplicities are not supported in our
modelling strategy and code generation.
We typically make use of the ContainerList<T>, this is a convenience collection that sets the owner or container object.
A composite property with an upper bound of 1 (A026 and A027) is a ContainerList<T> in the POCO as well. Containment is then handled by one mechanism for every composite property, and the list enforces the upper bound; see ContainerList. The DTO holds only the reference, so there the property is a single Guid.
A [1..1] ◆--> [0..1] B
_ _ _ _ _ _ _ _
| | [1..1] [0..1] | |
| A |◆------------------>| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
B.Container
POCO: A.prop_b
B.Container
SQL: B.prop_a
public class A {
/// <summary>
/// Gets or sets the unique identifier of <see cref="B"/>
/// that may be contained by <see cref="A"/>
/// </summary>
public Guid? Prop_b { get; set; }
}
public class B {
/// <summary>
/// The Container <see cref="A"/>
/// </summary>
public Guid Container { get; set; }
}
public class A {
/// <summary>
/// Initializes a new instance of the <see cref="A"/> class.
/// </summary>
public A()
{
this.Prop_b = new ContainerList<B>(this);
}
/// <summary>
/// Gets or sets the instance of <see cref="B"/>
/// that may be contained by <see cref="A"/>
/// </summary>
public ContainerList<B> Prop_b { get; set; }
}
public class B {
/// <summary>
/// The Container <see cref="A"/>
/// </summary>
public A Container { get; set; }
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY,
a_id UUID NOT NULL
)
ALTER TABLE "B" ADD CONSTRAINT fk_a FOREIGN KEY (a_id) REFERENCES "A"("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
A [1..1] ◆--> [1..1] B
_ _ _ _ _ _ _ _
| | [1..1] [1..1] | |
| A |◆------------------>| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
B.Container
POCO: A.prop_b
B.Container
SQL: B.prop_a
public class A {
/// <summary>
/// Gets or sets the unique identifier of <see cref="B"/>
/// that is contained by <see cref="A"/>
/// </summary>
public Guid Prop_b { get; set; }
}
public class B {
/// <summary>
/// The Container <see cref="A"/>
/// </summary>
public Guid Container { get; set; }
}
public class A {
/// <summary>
/// Initializes a new instance of the <see cref="A"/> class.
/// </summary>
public A()
{
this.Prop_b = new ContainerList<B>(this);
}
/// <summary>
/// Gets or sets the instance of <see cref="B"/>
/// that is contained by <see cref="A"/>
/// </summary>
public ContainerList<B> Prop_b { get; set; }
}
public class B {
/// <summary>
/// The Container <see cref="A"/>
/// </summary>
public A Container { get; set; }
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY,
a_id UUID NOT NULL
)
ALTER TABLE "B" ADD CONSTRAINT fk_a FOREIGN KEY (a_id) REFERENCES "A"("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
A [1..1] ◆--> [0..*] B
_ _ _ _ _ _ _ _
| | [1..1] [0..*] | |
| A |◆------------------>| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
B.Container
POCO: A.prop_b
B.Container
SQL: B.prop_a
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// that are contained by <see cref="A"/>
/// </summary>
public List<Guid> Prop_b { get; set; } = [];
}
public class B {
/// <summary>
/// The Container <see cref="A"/>
/// </summary>
public Guid Container { get; set; }
}
public class A {
/// <summary>
/// Initializes a new instance of the <see cref="A"/> class.
/// </summary>
public A()
{
this.Prop_b = new ContainerList<B>(this);
}
/// <summary>
/// Gets or sets the instances of <see cref="B"/>
/// that are contained by <see cref="A"/>
/// </summary>
public ContainerList<B> Prop_b { get; set; }
}
public class B {
/// <summary>
/// The Container <see cref="A"/>
/// </summary>
public A Container { get; set; }
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY,
a_id UUID NOT NULL
)
ALTER TABLE "B" ADD CONSTRAINT fk_a FOREIGN KEY (a_id) REFERENCES "A"("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
A [1..1] ◆--> [1..*] B
_ _ _ _ _ _ _ _
| | [1..1] [1..*] | |
| A |◆------------------>| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
B.Container
POCO: A.prop_b
B.Container
SQL: B.prop_a
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// that are contained by <see cref="A"/>
/// </summary>
public List<Guid> Prop_b { get; set; } = [];
}
public class B {
/// <summary>
/// The Container <see cref="A"/>
/// </summary>
public Guid Container { get; set; }
}
public class A {
/// <summary>
/// Initializes a new instance of the <see cref="A"/> class.
/// </summary>
public A()
{
this.Prop_b = new ContainerList<B>(this);
}
/// <summary>
/// Gets or sets the instances of <see cref="B"/>
/// that are contained by <see cref="A"/>
/// </summary>
public ContainerList<B> Prop_b { get; set; }
}
public class B {
/// <summary>
/// The Container <see cref="A"/>
/// </summary>
public A Container { get; set; }
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY,
a_id UUID NOT NULL
)
ALTER TABLE "B" ADD CONSTRAINT fk_a FOREIGN KEY (a_id) REFERENCES "A"("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
A [1..1] ◆--> [n..*] B
_ _ _ _ _ _ _ _
| | [1..1] [n..*] | |
| A |◆------------------>| B |
|_ _ _ _| prop_a prop_b |_ _ _ _|
DTO: A.prop_b
B.Container
POCO: A.prop_b
B.Container
SQL: B.prop_a
public class A {
/// <summary>
/// Gets or sets the unique identifiers of <see cref="B"/>
/// that are contained by <see cref="A"/>
/// </summary>
public List<Guid> Prop_b { get; set; } = [];
}
public class B {
/// <summary>
/// The Container <see cref="A"/>
/// </summary>
public Guid Container { get; set; }
}
public class A {
/// <summary>
/// Initializes a new instance of the <see cref="A"/> class.
/// </summary>
public A()
{
this.Prop_b = new ContainerList<B>(this);
}
/// <summary>
/// Gets or sets the instances of <see cref="B"/>
/// that are contained by <see cref="A"/>
/// </summary>
public ContainerList<B> Prop_b { get; set; }
}
public class B {
/// <summary>
/// The Container <see cref="A"/>
/// </summary>
public A Container { get; set; }
}
CREATE TABLE "A" (
id UUID PRIMARY KEY
)
CREATE TABLE "B" (
id UUID PRIMARY KEY,
a_id UUID NOT NULL
)
ALTER TABLE "B" ADD CONSTRAINT fk_a FOREIGN KEY (a_id) REFERENCES "A"("id") ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE;
copyright @ Starion Group S.A.
- Home
- uml4net Tools
- Code Generation Tutorial
- Primitive Types Mapping
- Profiles and StereoTypes
- Code Generation Conventions
- UML Handlebars Helpers
- Generating uml4net
- Developers Experience
- SBOM
- Design Decisions