dotnet/efcore · error · InvalidOperationException

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

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. Cosmos requires every trigger to declare a TriggerType (Pre/Post) via CosmosTriggerBuilderExtensions.HasTriggerType; without it the provider cannot register the trigger in the container.

Solutions

  1. Chain .HasTriggerType(TriggerType.Pre) or .HasTriggerType(TriggerType.Post) onto the trigger builder returned by HasTrigger(...).
  2. Confirm the trigger builder is not null (HasTrigger may return null if conflicting configuration exists).
  3. Re-run model validation to ensure the type annotation is now set.

Example fix

// before
modelBuilder.Entity<Doc>().HasTrigger("ValidateDoc");

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

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: Calling HasTrigger("name") on an entity but never chaining .HasTriggerType(TriggerType.Pre/Post) on the returned builder.

Common situations: Defining a trigger by name only and forgetting the Cosmos-specific type; refactoring trigger setup and dropping the type line; converting triggers from data annotations that do not carry the Cosmos type.

Related errors


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

Appendix: 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 3a2006ef56)