{"record":{"id":"dc57c0c82c33eb8f","repo":"dotnet/efcore","slug":"the-partition-key-property-property1-on-enti","errorCode":null,"errorMessage":"The partition key property '{property1}' on '{entityType1}' is mapped as '{storeName1}', but the partition key property '{property2}' on '{entityType2}' is mapped as '{storeName2}'. All partition key properties need to be mapped to the same store property for entity types mapped to the same container.","messagePattern":"The partition key property '(.+?)' on '(.+?)' is mapped as '(.+?)', but the partition key property '(.+?)' on '(.+?)' is mapped as '(.+?)'\\. All partition key properties need to be mapped to the same store property for entity types mapped to the same container\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs","lineNumber":179,"sourceCode":"            }\n            else\n            {\n                if (partitionKeyStoreNames.Count != storeNames.Count)\n                {\n                    throw new InvalidOperationException(\n                        CosmosStrings.NoPartitionKey(\n                            firstEntityType.DisplayName(),\n                            string.Join(\",\", partitionKeyStoreNames),\n                            entityType.DisplayName(),\n                            string.Join(\",\", storeNames),\n                            container));\n                }\n\n                for (var i = 0; i < storeNames.Count; i++)\n                {\n                    if (!string.Equals(storeNames[i], partitionKeyStoreNames[i], StringComparison.Ordinal))\n                    {\n                        throw new InvalidOperationException(\n                            CosmosStrings.PartitionKeyStoreNameMismatch(\n                                firstEntityType.GetPartitionKeyPropertyNames()[i],\n                                firstEntityType.DisplayName(),\n                                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)","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs#L161-L197","documentation":"CosmosModelValidator.ValidateSharedContainerCompatibility throws InvalidOperationException(CosmosStrings.PartitionKeyStoreNameMismatch) when two entity types in the same container declare partition keys with the same count but their JSON store names (the value returned by GetJsonPropertyName for each partition key property) differ at the same position. Cosmos requires every type in a shared container to map its partition key properties to the same JSON property name(s) so the server-side partition function is consistent.","triggerScenarios":"EntityA.HasPartitionKey(a => a.TenantId) maps TenantId to JSON \"tenantId\", but EntityB.HasPartitionKey(b => b.TenantKey) (same container) maps TenantKey to JSON \"tenantKey\"; renaming a partition key property without renaming its JSON mapping; using ToJsonProperty on one partition key property but not the corresponding one on a sibling entity type.","commonSituations":"Sharing a container between entity types that named the partition key differently in C# but forgot to align the JSON name; refactor/rename of a partition key property on one type only; types added later to an existing shared container without aligning JSON names.","solutions":["Align the JSON property name of each partition key property across all entity types in the shared container using ToJsonProperty/HasJsonPropertyName.","Use the same C# property name (and therefore the same default JSON name) for the partition key across all types.","If the names genuinely differ, move the types into separate containers.","Validate the model at startup so the mismatch surfaces before the first query."],"exampleFix":"// before - throws: same container, JSON names differ at position 0\nmodelBuilder.Entity<A>()\n    .HasPartitionKey(a => a.TenantId)   // -> JSON \"tenantId\"\n    .ToContainer(\"Shared\");\nmodelBuilder.Entity<B>()\n    .HasPartitionKey(b => b.TenantKey)  // -> JSON \"tenantKey\"\n    .ToContainer(\"Shared\");\n\n// after - align the JSON name on B's partition key\nmodelBuilder.Entity<B>()\n    .HasPartitionKey(b => b.TenantKey)\n    .ToContainer(\"Shared\");\nmodelBuilder.Entity<B>()\n    .Property(b => b.TenantKey).ToJsonProperty(\"tenantId\");","handlingStrategy":"validation","validationCode":"// Ensure the JSON property names of partition key properties line up.\nstatic bool PartitionKeyJsonNamesAligned(IReadOnlyList<IEntityType> types)\n{\n    var reference = types[0].GetPartitionKeyPropertyNames()\n        .Select(n => types[0].FindProperty(n)!.GetJsonPropertyName()).ToList();\n    return types.Skip(1).All(t => t.GetPartitionKeyPropertyNames()\n        .Select(n => t.FindProperty(n)!.GetJsonPropertyName()).SequenceEqual(reference));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Align partition key JSON property names across all entity types in a shared container using ToJsonProperty.","Use the same C# partition key property name across types so the default JSON name matches.","Audit container-shared types whenever you rename a partition key property.","Validate the model at startup to surface JSON name mismatches early."],"tags":["ef-core","cosmos","model-validation","partition-key","shared-container"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}