{"record":{"id":"200b4a87da5bd01f","repo":"dotnet/efcore","slug":"the-discriminator-value-for-entitytype1-is-d","errorCode":null,"errorMessage":"The discriminator value for '{entityType1}' is '{discriminatorValue}' which is the same for '{entityType2}'. Every concrete entity type mapped to the container '{container}' must have a unique discriminator value.","messagePattern":"The discriminator value for '(.+?)' is '(.+?)' which is the same for '(.+?)'\\. Every concrete entity type mapped to the container '(.+?)' must have a unique discriminator value\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs","lineNumber":212,"sourceCode":"            }\n\n            if (entityType.ClrType.IsInstantiable()\n                && entityType.GetContainingPropertyName() == null)\n            {\n                if (entityType.FindDiscriminatorProperty() == null)\n                {\n                    throw new InvalidOperationException(CosmosStrings.NoDiscriminatorProperty(entityType.DisplayName(), container));\n                }\n\n                var discriminatorValue = entityType.GetDiscriminatorValue();\n                if (discriminatorValue == null)\n                {\n                    throw new InvalidOperationException(CosmosStrings.NoDiscriminatorValue(entityType.DisplayName(), container));\n                }\n\n                if (discriminatorValues.TryGetValue(discriminatorValue, out var duplicateEntityType))\n                {\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(","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs#L194-L230","documentation":"CosmosModelValidator.ValidateSharedContainerCompatibility throws InvalidOperationException(CosmosStrings.DuplicateDiscriminatorValue) when two instantiable entity types sharing a container are assigned the same discriminator value. EF builds a Dictionary<object, IEntityType> as it iterates and throws on the first duplicate; each concrete type in a shared container must have a unique discriminator value so documents can be routed to exactly one CLR type.","triggerScenarios":"Two entity types in the same container both call HasValue(\"default\") or HasValue(0); a TPH hierarchy where two sibling types reuse the same discriminator value; default discriminator values colliding after merging previously separate containers.","commonSituations":"Merging two containers whose types happened to share discriminator values; copy-paste of HasValue across IEntityTypeConfiguration classes; using a default like \"Base\" for several types; discriminator value collisions after a type rename that lost its custom value.","solutions":["Give every instantiable type in the shared container a distinct discriminator value (e.g. HasValue(\"order\") vs HasValue(\"invoice\")).","Use a generator or convention that produces unique values (e.g. the entity's simple CLR type name) so manual edits cannot collide.","If two types share a value intentionally because they are the same shape, merge them or map them via inheritance with a base value.","Validate the model at startup to surface collisions before any data is written."],"exampleFix":"// before - throws: both types use the same discriminator value\nmodelBuilder.Entity<Order>()\n    .ToContainer(\"Docs\")\n    .HasDiscriminator(o => o.Kind).HasValue(\"doc\");\nmodelBuilder.Entity<Invoice>()\n    .ToContainer(\"Docs\")\n    .HasDiscriminator(i => i.Kind).HasValue(\"doc\");\n\n// after - unique values\nmodelBuilder.Entity<Order>()\n    .ToContainer(\"Docs\")\n    .HasDiscriminator(o => o.Kind).HasValue(\"order\");\nmodelBuilder.Entity<Invoice>()\n    .ToContainer(\"Docs\")\n    .HasDiscriminator(i => i.Kind).HasValue(\"invoice\");","handlingStrategy":"validation","validationCode":"// Pre-validate: every shared-container discriminator value must be unique.\nstatic bool DiscriminatorValuesAreUnique(IReadOnlyList<IEntityType> types)\n{\n    var values = types.Where(t => t.ClrType.IsInstantiable() && t.GetContainingPropertyName() is null)\n        .Select(t => t.GetDiscriminatorValue()).ToList();\n    return values.Distinct().Count() == values.Count;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a convention that derives the discriminator value from the CLR type name to avoid collisions.","After merging containers, audit every shared type's discriminator value.","Avoid copy-paste of HasValue across IEntityTypeConfiguration classes.","Validate the model at startup to surface collisions before any data is written."],"tags":["ef-core","cosmos","model-validation","discriminator","shared-container"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}