Repository navigation
PreparedTrigger_MaintainHierarchyLevel
Use PreparedTrigger_MaintainHierarchyLevel<TEntity> for a tree with a nullable long foreign key to the same entity and a stored int level. Expose the level as a getter with [DefaultValue(0), DatabaseGenerated(DatabaseGeneratedOption.Computed)]. Import Blueprint.Entities.Triggers.PreparedTriggers and place this method inside Category.
/// <summary>Defines the trigger that maintains the category hierarchy levels.</summary>
/// <returns>The prepared hierarchy-level trigger.</returns>
public override List<BlueprintEntityTrigger> getDatabaseTriggers()
{
return [new PreparedTrigger_MaintainHierarchyLevel<Category>("TR_Categories_Level", nameof(ParentID), nameof(Level))];
}Register Category to install its trigger. The first installation calculates levels for existing rows in the same transaction that creates the trigger. An existing cycle causes installation to roll back.
A root has level zero. Inserting a node or changing its parent updates the depth of the affected subtree in the same transaction. Multi-row operations use the final parent relationships, including moves that affect overlapping subtrees. A cyclic change fails and rolls back. Ordinary edits to unrelated columns leave the levels in place.