{"record":{"id":"09a3a6a30c210de7","repo":"dotnet/efcore","slug":"the-isdiscriminatormappingcomplete-setting-was-con","errorCode":null,"errorMessage":"The IsDiscriminatorMappingComplete setting was configured to '{isDiscriminatorMappingComplete1}' on '{entityType1}', but on '{entityType2}' it was configured to '{isDiscriminatorMappingComplete2}'. All entity types mapped to the same container '{container}' must be configured with the same 'IsDiscriminatorMappingComplete' value.","messagePattern":"The IsDiscriminatorMappingComplete setting was configured to '(.+?)' on '(.+?)', but on '(.+?)' it was configured to '(.+?)'\\. All entity types mapped to the same container '(.+?)' must be configured with the same 'IsDiscriminatorMappingComplete' value\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs","lineNumber":229,"sourceCode":"                {\n                    throw new InvalidOperationException(\n                        CosmosStrings.DuplicateDiscriminatorValue(\n                            entityType.DisplayName(),\n                            discriminatorValue,\n                            duplicateEntityType.DisplayName(),\n                            container));\n                }\n\n                discriminatorValues[discriminatorValue] = entityType;\n\n                var currentIsDiscriminatorMappingComplete = entityType.GetIsDiscriminatorMappingComplete();\n                if (isDiscriminatorMappingComplete == null)\n                {\n                    isDiscriminatorMappingComplete = currentIsDiscriminatorMappingComplete;\n                }\n                else if (currentIsDiscriminatorMappingComplete != isDiscriminatorMappingComplete)\n                {\n                    throw new InvalidOperationException(\n                        CosmosStrings.IsDiscriminatorMappingCompleteMismatch(\n                            isDiscriminatorMappingComplete, firstEntityType.DisplayName(), entityType.DisplayName(),\n                            currentIsDiscriminatorMappingComplete, container));\n                }\n            }\n\n            var currentAnalyticalTtl = entityType.GetAnalyticalStoreTimeToLive();\n            if (currentAnalyticalTtl != null)\n            {\n                if (analyticalTtl == null)\n                {\n                    analyticalTtl = currentAnalyticalTtl;\n                }\n                else if (analyticalTtl != currentAnalyticalTtl)\n                {\n                    var conflictingEntityType = mappedTypes.First(et => et.GetAnalyticalStoreTimeToLive() != null);\n                    throw new InvalidOperationException(\n                        CosmosStrings.AnalyticalTTLMismatch(","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs#L211-L247","documentation":"The IsDiscriminatorMappingComplete setting (whether the discriminator mapping is considered complete/abstract) must be consistent across all entity types sharing a container. CosmosModelValidator throws InvalidOperationException via CosmosStrings.IsDiscriminatorMappingCompleteMismatch when one type is configured complete and another is not, because a single container needs one coherent discriminator policy.","triggerScenarios":"Calling IsComplete() (or not) on one entity type in a shared container but configuring the opposite on another; mixing abstract/incomplete discriminator mappings across roots in one container.","commonSituations":"Adding a new type to a shared container without matching the existing IsDiscriminatorMappingComplete convention; partial refactoring that flips the setting on only some types.","solutions":["Apply the same IsDiscriminatorMappingComplete configuration (complete or not) to every entity type sharing the container.","Centralize the setting in a shared convention so all roots in a container agree.","If a type needs a different policy, map it to a separate container."],"exampleFix":"// before (inconsistent setting in one container)\nmodelBuilder.Entity<Cat>(b => { b.ToContainer(\"pets\"); b.HasDiscriminator(c => c.Kind).IsComplete(); });\nmodelBuilder.Entity<Dog>(b => { b.ToContainer(\"pets\"); b.HasDiscriminator(d => d.Kind); }); // default (not complete)\n\n// after (both consistent)\nmodelBuilder.Entity<Cat>(b => { b.ToContainer(\"pets\"); b.HasDiscriminator(c => c.Kind).IsComplete(); });\nmodelBuilder.Entity<Dog>(b => { b.ToContainer(\"pets\"); b.HasDiscriminator(d => d.Kind).IsComplete(); });","handlingStrategy":"validation","validationCode":"// IsDiscriminatorMappingComplete must be consistent within a container.\nvar byContainer = modelBuilder.Model.GetEntityTypes()\n    .Where(e => e.FindPrimaryKey() != null && e.GetContainer() != null && e.ClrType.IsInstantiable())\n    .GroupBy(e => e.GetContainer());\nforeach (var g in byContainer.Where(g => g.Count() > 1))\n{\n    var settings = g.Select(e => e.GetIsDiscriminatorMappingComplete()).Distinct().ToList();\n    if (settings.Count > 1)\n        throw new InvalidOperationException($\"Inconsistent IsDiscriminatorMappingComplete in {g.Key}.\");\n}","typeGuard":null,"tryCatchPattern":"try { context.Database.EnsureCreated(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"IsDiscriminatorMappingComplete\"))\n{ throw new InvalidOperationException(\"Apply the same IsDiscriminatorMappingComplete across the shared container.\", ex); }","preventionTips":["Apply IsDiscriminatorMappingComplete via a shared convention per container.","When adding a type to a shared container, match the existing setting.","Add a build-time test asserting one IsDiscriminatorMappingComplete value per container."],"tags":["cosmos","discriminator","shared-container","model-validation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}