Skip to content

PreparedTrigger_MaintainFirstValue

github-actions[bot] edited this page Dec 6, 2026 · 3 revisions

Use PreparedTrigger_MaintainFirstValue<TSource, TTarget> on a child entity to store a value from its first row on the parent. The following method belongs inside ProductPhoto and copies the first photo's URL into Product.PrimaryImageURL. Import Blueprint.Entities.Triggers.PreparedTriggers.

/// <summary>Defines how to maintain the first photo's URL on each product.</summary>
/// <returns>The prepared first-value trigger.</returns>
public override List<BlueprintEntityTrigger> getDatabaseTriggers()
{
    return [new PreparedTrigger_MaintainFirstValue<ProductPhoto, Product>(
        "TR_ProductPhotos_PrimaryImageURL", nameof(ProductID), nameof(SortOrder), nameof(URL), nameof(Product.PrimaryImageURL))];
}

Use a foreign key to the parent ID, a mapped integer sort column, and compatible mapped scalar columns for the value and the nullable target. Give the target a getter and mark it with [DatabaseGenerated(DatabaseGeneratedOption.Computed)]. The trigger sorts ascending by the specified column and then by the source ID. If the parent has no source rows, it stores null.

Register ProductPhoto to install its trigger. The first installation populates existing products in the same transaction that creates the trigger. Subsequent inserts, updates, and deletes recalculate the affected parents. Moving a row refreshes both parents.

Entity triggers and common imports

Clone this wiki locally