dotnet/efcore · error · InvalidOperationException

Trigger ' ' on entity type ' ' does not have a trigger…

Error message

Trigger '{trigger}' on entity type '{entityType}' does not have a trigger operation configured. Use 'HasTriggerOperation()' to configure the trigger operation.

What it means

Thrown by CosmosModelValidator.ValidateTriggerOperation when trigger.GetTriggerOperation() returns null. Besides a TriggerType, every Cosmos trigger must declare a TriggerOperation (Create/Replace/Delete/All) via CosmosTriggerBuilderExtensions.HasTriggerOperation.

Solutions

  1. Chain .HasTriggerOperation(TriggerOperation.All) (or Create/Replace/Delete as appropriate) onto the trigger builder.
  2. Verify the builder is non-null before chaining.
  3. Re-validate the model to confirm both TriggerType and TriggerOperation are set.

Example fix

// before
modelBuilder.Entity<Doc>()
    .HasTrigger("ValidateDoc")!
    .HasTriggerType(TriggerType.Pre);

// after
modelBuilder.Entity<Doc>()
    .HasTrigger("ValidateDoc")!
    .HasTriggerType(TriggerType.Pre)
    .HasTriggerOperation(TriggerOperation.Create);
Defensive patterns

Strategy: validation

Validate before calling

// Ensure every trigger has an operation.
foreach (var et in modelBuilder.Model.GetEntityTypes())
foreach (var t in et.GetTriggers())
    if (t.GetTriggerOperation() is null)
        throw new InvalidOperationException($"Trigger {t.ModelName} on {et.DisplayName()} needs HasTriggerOperation().");

Prevention

When it happens

Trigger: Calling HasTrigger(...) and HasTriggerType(...) but never chaining .HasTriggerOperation(TriggerOperation.Create|Replace|Delete|All).

Common situations: Setting only the type and assuming a default operation; partial copy of trigger config; refactoring away the operation line.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/26ee8a2590bd1f6d. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs:820

            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(
                CosmosStrings.TriggerMissingOperation(trigger.ModelName, entityType.DisplayName()));
        }
    }
}

View on GitHub (pinned to 3a2006ef56)