{"record":{"id":"3cf3fbdc270d08be","repo":"dotnet/efcore","slug":"trigger-trigger-on-entity-type-entitytype","errorCode":null,"errorMessage":"Trigger '{trigger}' on entity type '{entityType}' does not have a trigger type configured. Use 'HasTriggerType()' to configure the trigger type.","messagePattern":"Trigger '(.+?)' on entity type '(.+?)' does not have a trigger type configured\\. Use 'HasTriggerType\\(\\)' to configure the trigger type\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs","lineNumber":802,"sourceCode":"            throw new InvalidOperationException(\n                CosmosStrings.TriggerOnDerivedType(trigger.ModelName, entityType.DisplayName(), entityType.BaseType.DisplayName()));\n        }\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    protected virtual void ValidateTriggerType(\n        ITrigger trigger,\n        IEntityType entityType,\n        IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)\n    {\n        if (trigger.GetTriggerType() == null)\n        {\n            throw new InvalidOperationException(\n                CosmosStrings.TriggerMissingType(trigger.ModelName, entityType.DisplayName()));\n        }\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    protected virtual void ValidateTriggerOperation(\n        ITrigger trigger,\n        IEntityType entityType,\n        IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)\n    {\n        if (trigger.GetTriggerOperation() == null)\n        {\n            throw new InvalidOperationException(","sourceCodeStart":784,"sourceCodeEnd":820,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs#L784-L820","documentation":"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.","triggerScenarios":"Calling HasTrigger(\"myTrigger\") without chaining HasTriggerType(...), or adding a trigger via convention/migration that did not set the type facet.","commonSituations":"Following a partial example that only names the trigger. Migrating trigger configuration where the HasTriggerType call was dropped.","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."],"exampleFix":"// before\nmodelBuilder.Entity<Order>()\n    .HasTrigger(\"validateOrder\");\n\n// after\nmodelBuilder.Entity<Order>()\n    .HasTrigger(\"validateOrder\", CosmosTriggerType.Pre, CosmosTriggerOperation.Create);","handlingStrategy":"validation","validationCode":"foreach (var et in modelBuilder.Model.GetEntityTypes())\n{\n    foreach (var trigger in et.GetTriggers())\n    {\n        if (trigger.GetTriggerType() is null)\n            throw new InvalidOperationException($\"Trigger {trigger.ModelName} on {et.DisplayName()} has no trigger type.\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cosmos","ef-core","model-validation","triggers"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}