Skip to content

Property Constraints

Alex Fox Gill edited this page May 11, 2016 · 9 revisions

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.

Constraint types

  • OneToOnePropertyConstraint (source): Enforces the inverse one-to-one relationship (if foo.Bar == bar then bar.Foo == foo)
  • OneToManyPropertyConstraint (source): Enforces the inverse many-to-one relationship of a collection property (if foo.Bars.Contains(bar) then bar.Foo == bar)
  • ManyToOnePropertyConstraint (source): Enforces the inverse one-to-many relationship (if foo.Bar == bar then bar.Foos.Contains(foo))
  • ManyToManyPropertyConstraint (source): Enforces the inverse many-to-many relationship (if foo.Bar.Contains(bar) then bar.Foos.Contains(foo))
  • ForeignKeyConstraint (source): Enforces a foreign key constraint (if foo.Bar == bar then foo.BarId == bar.Id)
Clone this wiki locally