dotnet/efcore · error · InvalidOperationException
Trigger '{trigger}' on entity type '{entityType}' does not h
Error message
Trigger '{trigger}' on entity type '{entityType}' does not have a trigger type configured. Use 'HasTriggerType()' to configure the trigger type. What it means
Thrown by CosmosModelValidator.ValidateTriggerType when trigger.GetTriggerType() returns null. A Cosmos pre-trigger needs its type (Pre/Post) declared so EF Core can emit it into the container trigger definition; without it the trigger is incomplete and rejected at validation.
Source
Thrown at src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs:802
throw new InvalidOperationException(
CosmosStrings.TriggerOnDerivedType(trigger.ModelName, entityType.DisplayName(), entityType.BaseType.DisplayName()));
}
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected virtual void ValidateTriggerType(
ITrigger trigger,
IEntityType entityType,
IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
{
if (trigger.GetTriggerType() == null)
{
throw new InvalidOperationException(
CosmosStrings.TriggerMissingType(trigger.ModelName, entityType.DisplayName()));
}
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected virtual void ValidateTriggerOperation(
ITrigger trigger,
IEntityType entityType,
IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
{
if (trigger.GetTriggerOperation() == null)
{
throw new InvalidOperationException(View on GitHub (pinned to dbf9771522)
Solutions
- Chain .HasTriggerType(CosmosTriggerType.Pre) (or Post) on the trigger builder returned by HasTrigger.
- Re-run model validation after editing to confirm no other trigger facets are missing.
Example fix
// before
modelBuilder.Entity<Order>()
.HasTrigger("validateOrder");
// after
modelBuilder.Entity<Order>()
.HasTrigger("validateOrder", CosmosTriggerType.Pre, CosmosTriggerOperation.Create); Defensive patterns
Strategy: validation
Validate before calling
foreach (var et in modelBuilder.Model.GetEntityTypes())
{
foreach (var trigger in et.GetTriggers())
{
if (trigger.GetTriggerType() is null)
throw new InvalidOperationException($"Trigger {trigger.ModelName} on {et.DisplayName()} has no trigger type.");
}
} Prevention
- Prefer the HasTrigger(name, type, operation) overload so type and operation are never omitted.
- Add a model-validation test asserting GetTriggerType() is non-null for every trigger.
When it happens
Trigger: Calling HasTrigger("myTrigger") without chaining HasTriggerType(...), or adding a trigger via convention/migration that did not set the type facet.
Common situations: Following a partial example that only names the trigger. Migrating trigger configuration where the HasTriggerType call was dropped.
Related errors
- Trigger '{trigger}' is defined on entity type '{entityType}'
- Trigger '{trigger}' on entity type '{entityType}' does not h
- A full-text index on '{entityType}' is defined over multiple
- A full-text index is defined for `{entityType}.{property}`,
- The property '{propertyType} {structuralType}.{property}' ha
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/3cf3fbdc270d08be.
Report an issue: GitHub.