{"record":{"id":"c7a7bb2341b4ae4d","repo":"dotnet/efcore","slug":"the-entity-type-entitytype-is-sharing-the-cont","errorCode":null,"errorMessage":"The entity type '{entityType}' is sharing the container '{container}' with other types, but does not have a discriminator property configured. Configure a discriminator property and assign a unique value for this entity type.","messagePattern":"The entity type '(.+?)' is sharing the container '(.+?)' with other types, but does not have a discriminator property configured\\. Configure a discriminator property and assign a unique value for this entity type\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs","lineNumber":201,"sourceCode":"                                partitionKeyStoreNames[i],\n                                entityType.GetPartitionKeyPropertyNames()[i],\n                                entityType.DisplayName(),\n                                storeNames[i]));\n                    }\n                }\n            }\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","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs#L183-L219","documentation":"CosmosModelValidator.ValidateSharedContainerCompatibility throws InvalidOperationException(CosmosStrings.NoDiscriminatorProperty) when an instantiable entity type (ClrType.IsInstantiable()) sharing a container with other types has no discriminator property configured. When multiple entity types map to the same container, Cosmos needs a discriminator to tell documents apart, and EF needs to know which property holds it. The check fires only for document roots (not embedded).","triggerScenarios":"Two or more concrete entity types mapped to the same container via HasContainerName, none of which calls HasDiscriminator; sharing a container for unrelated types without configuring a discriminator; disabling the default discriminator convention on a shared-container type.","commonSituations":"Sharing containers between unrelated entity types for cost reasons and skipping discriminator setup; a convention that removes the default discriminator; entity types that used to be in separate containers and were merged.","solutions":["Configure a discriminator property on every instantiable entity type sharing the container: modelBuilder.Entity<A>().HasDiscriminator(x => x.Type).HasValue(\"a\").","If the types are part of an inheritance hierarchy, configure the discriminator on the root and values on each derived type.","If you did not intend to share a container, give each type its own container via HasContainerName.","Avoid disabling the discriminator convention on types that share a container."],"exampleFix":"// before - throws: A and B share a container with no discriminator\nmodelBuilder.Entity<A>().ToContainer(\"Shared\");\nmodelBuilder.Entity<B>().ToContainer(\"Shared\");\n\n// after - configure a discriminator property and value on each\nmodelBuilder.Entity<A>()\n    .ToContainer(\"Shared\")\n    .HasDiscriminator(a => a.Kind).HasValue(\"a\");\nmodelBuilder.Entity<B>()\n    .ToContainer(\"Shared\")\n    .HasDiscriminator(b => b.Kind).HasValue(\"b\");","handlingStrategy":"validation","validationCode":"// Pre-validate: every instantiable document-root type in a shared container must have a discriminator property.\nstatic bool AllHaveDiscriminators(IReadOnlyList<IEntityType> types)\n    => types.Where(t => t.ClrType.IsInstantiable() && t.GetContainingPropertyName() is null)\n        .All(t => t.FindDiscriminatorProperty() is not null);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure HasDiscriminator on every instantiable entity type in a shared container.","Avoid disabling the discriminator convention on shared-container types.","If types were not meant to share, give them separate containers.","Validate the model at startup to catch missing discriminators 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"}