-
Notifications
You must be signed in to change notification settings - Fork 12
Property Constraints
Property Constraints implement the IPropertyConstraint
(source) interface. A Property Constraint applies to a single property on an entity type, identified by the PropInfo property.
It is expected that for any class implementing IPropertyConstraint
, the generic version IPropertyConstraint<THost, TProperty>
should also be implemented, with the generic THost
being the entity which hosts the property, and TProperty
being the type of the property. This interface has one method, void Rebind(THost host, TProperty previousValue, TProperty value)
. This method is called whenever the property is set on the host entity. This allows the constraint to enforce itself.
Constraints obey the Single Responsibility Principle, and as such are one-way. For example, in order to apply a Many-to-Many relationship in both directions, two ManyToManyConstraint
instances must be supplied to LazyEntityGraph: one in each direction.
-
OneToOnePropertyConstraint
(source): Enforces the inverse one-to-one relationship (iffoo.Bar == bar
thenbar.Foo == foo
) -
OneToManyPropertyConstraint
(source): Enforces the inverse many-to-one relationship of a collection property (iffoo.Bars.Contains(bar)
thenbar.Foo == bar
) -
ManyToOnePropertyConstraint
(source): Enforces the inverse one-to-many relationship (iffoo.Bar == bar
thenbar.Foos.Contains(foo)
) -
ManyToManyPropertyConstraint
(source): Enforces the inverse many-to-many relationship (iffoo.Bar.Contains(bar)
thenbar.Foos.Contains(foo)
) -
ForeignKeyConstraint
(source): Enforces a foreign key constraint (iffoo.Bar == bar
thenfoo.BarId == bar.Id
)