Skip to content

Entity Triggers

github-actions[bot] edited this page Dec 6, 2026 · 1 revision

Declare a trigger in C# when a stored value must stay in sync with other rows or columns. SQL Server applies the rule in the same transaction as the write, including writes from another SQL client. A rollback also rolls back the change made by the trigger.

Contents

BlueprintEntityTrigger

BlueprintEntityTrigger is the abstract base class for entity triggers. Each trigger exposes these members.

Member Purpose
Name Identifies the trigger or provides the prefix for a group of SQL triggers.
PropertyName Identifies the mapped entity property used by the rule.
Conditions Lists the data events the rule handles using EBlueprintEntityTriggerConditions. The available events are Insert, Update, and Delete.
SqlStatement Exposes the primary SQL statement once generated. Prepared triggers generate it during installation.
Install(BlueprintDatabase database) Installs the trigger in the specified database.

Declare a trigger

Override getDatabaseTriggers() on the source entity and return a List<BlueprintEntityTrigger>. SQL Server registration discovers the lists on registered entities and their mapped relationships, then installs each list in order after creating the schema. Use a trigger name that is unique within its SQL schema. For EF writes to a table with triggers, set UseSqlOutputClause = false on its [Entity] attribute.

The prepared-trigger pages use independent examples and share these imports.

using Blueprint.Entities;
using Blueprint.Entities.Annotations;
using Blueprint.Entities.Triggers;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;

Prepared Triggers

The Blueprint.Entities.Triggers.PreparedTriggers namespace contains the built-in SQL Server rules. Each rule's page explains which properties it needs and when it runs.

Registration and existing rows

Registration creates missing triggers. The count, first-value, hierarchy-level, calculated-value and parent minimum rules also populate existing rows when they install. The value-history rule begins recording with the first qualifying change after installation. Prepared triggers also support explicit Install(database) calls for registered entities. Manage any trigger already present in the database with an explicit SQL migration when its definition needs to change. Schema Synchronization

Related topics

Data Annotations · Relationships · Transactions

Clone this wiki locally