{"record":{"id":"9c65571506323535","repo":"dotnet/efcore","slug":"the-entity-type-entitytype-is-sharing-the-cont-9c6557","errorCode":null,"errorMessage":"The entity type '{entityType}' is sharing the container '{container}' with other types, but does not have a discriminator value configured. Configure a unique discriminator value for this entity type.","messagePattern":"The entity type '(.+?)' is sharing the container '(.+?)' with other types, but does not have a discriminator value configured\\. Configure a unique discriminator value for this entity type\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs","lineNumber":207,"sourceCode":"            }\n\n            if (mappedTypes.Count == 1)\n            {\n                break;\n            }\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;","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs#L189-L225","documentation":"CosmosModelValidator.ValidateSharedContainerCompatibility throws InvalidOperationException(CosmosStrings.NoDiscriminatorValue) when an instantiable entity type sharing a container has a discriminator property configured but no discriminator value assigned (entityType.GetDiscriminatorValue() == null). EF needs a concrete value to write into the discriminator field for each document so it can route queries to the correct type.","triggerScenarios":"Calling HasDiscriminator(x => x.Kind) without a following HasValue(...); configuring a discriminator property via attribute or convention but never setting the value; abstract base types where the default convention would skip the value but the type became instantiable.","commonSituations":"Forgetting HasValue after HasDiscriminator; switching from default-discriminator conventions to explicit configuration and missing the value; discriminator value lost during a refactor.","solutions":["Add HasValue(...) right after HasDiscriminator for every instantiable type sharing the container.","If using attributes, make sure each type carries a [Discriminator] value (or whatever attribute the configuration reads).","If the type is meant to be abstract, ensure ClrType is abstract so IsInstantiable() returns false and skips this check.","Run model validation at startup to surface missing values before the first SaveChanges."],"exampleFix":"// before - throws: discriminator property set, no value\nmodelBuilder.Entity<A>()\n    .ToContainer(\"Shared\")\n    .HasDiscriminator(a => a.Kind);\n\n// after - assign a value\nmodelBuilder.Entity<A>()\n    .ToContainer(\"Shared\")\n    .HasDiscriminator(a => a.Kind).HasValue(\"a\");","handlingStrategy":"validation","validationCode":"// Pre-validate: every instantiable shared-container type with a discriminator must also have a value.\nstatic bool AllHaveDiscriminatorValues(IReadOnlyList<IEntityType> types)\n    => types.Where(t => t.ClrType.IsInstantiable() && t.GetContainingPropertyName() is null)\n        .All(t => t.GetDiscriminatorValue() is not null);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always chain HasValue(...) after HasDiscriminator(...).","Make abstract types abstract in CLR so IsInstantiable() returns false and skips the check.","Audit IEntityTypeConfiguration<T> classes to ensure HasValue is present after HasDiscriminator.","Validate the model at startup to surface missing values before SaveChanges."],"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"}