Entity Set References
Entity set references let you constraint sets of entities related to an outgoing entity.
Example
For example if you have an assertion to check that all runs contain at least one assertion
[Assertion]
public Constraint HasAtLeastOneAssertionSelection()
{
return Check.For(Times.All, (Run run) =>
Check.For(Times.AtLeastOnce, (AssertionSelection ia) =>
ia.RunId.IsEqualTo(run.Id)));
}
public EntitySetReference<AssertionSelection> IncludedAssertions =>
new(assertionSelection => assertionSelection.RunId.IsEqualTo(Id));
[Assertion]
public Constraint HasAtLeastOneAssertionSelection()
{
return Check.For(Times.All, (Run run) =>
run.IncludedAssertions.IsNotEmpty());
}
Note
When you can be sure that exactly zero or one entities are going to match the connecting constraint, then you can use entity references to model the relation.
Use Cases
Asserting existance of entites matching the connecting constraint
Use IsNotEmpty or IsEmpty to check if any entites matching the connecting constraint exist or not.
Asserting that entity is (not) contained in set
Use Contains to check if an entity (reference) is contained in a set.
Asserting that subset matches constraint
Use For to check if a subset matches a constraint. It can be used like the standalone For constraint, but only considers entities matching the connecting constraint.