{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs#L161-L197","documentation":"When the partition key property counts match but their JSON store names (ToJsonProperty) differ between entity types sharing a container, CosmosModelValidator throws InvalidOperationException via CosmosStrings.PartitionKeyStoreNameMismatch. Cosmos needs one physical partition key path, so every type must map its partition key to the same JSON property name.","triggerScenarios":"Two types share a container and both declare a partition key property, but one renames the partition key's JSON property via ToJsonProperty to a different name than the other.","commonSituations":"Renaming the partition key JSON property on one type only; legacy property names that differ across roots forced into one container; copy-paste of ToJsonProperty that diverges.","solutions":["Map the partition key property to the same JSON property name (ToJsonProperty) across all entity types in the shared container.","Remove conflicting ToJsonProperty renames so each type's partition key resolves to the same store path.","If names truly must differ, the types belong in separate containers."],"exampleFix":"// before (partition key JSON names diverge in one container)\nmodelBuilder.Entity<Order>().ToContainer(\"docs\").HasPartitionKey(o => o.TenantId)\n    .Property(o => o.TenantId).ToJsonProperty(\"tid\");\nmodelBuilder.Entity<Invoice>().ToContainer(\"docs\").HasPartitionKey(i => i.TenantId)\n    .Property(i => i.TenantId).ToJsonProperty(\"tenant_id\");\n\n// after (same JSON name for the partition key)\nmodelBuilder.Entity<Order>().ToContainer(\"docs\").HasPartitionKey(o => o.TenantId)\n    .Property(o => o.TenantId).ToJsonProperty(\"tenantId\");\nmodelBuilder.Entity<Invoice>().ToContainer(\"docs\").HasPartitionKey(i => i.TenantId)\n    .Property(i => i.TenantId).ToJsonProperty(\"tenantId\");","handlingStrategy":"validation","validationCode":"// Partition key JSON store names must match across types in a container.\nvar byContainer = modelBuilder.Model.GetEntityTypes()\n    .Where(e => e.FindPrimaryKey() != null && e.GetContainer() != null)\n    .GroupBy(e => e.GetContainer());\nforeach (var g in byContainer)\n{\n    var storeNames = g.Select(e => string.Join(\",\",\n        e.GetPartitionKeyPropertyNames().Select(n => e.FindProperty(n)?.GetJsonPropertyName()))).Distinct();\n    if (storeNames.Count() > 1)\n        throw new InvalidOperationException($\"Container {g.Key} has mismatched partition key JSON names.\");\n}","typeGuard":null,"tryCatchPattern":"try { context.Database.EnsureCreated(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"same store property\"))\n{ throw new InvalidOperationException(\"Map partition key properties to the same JSON name in the shared container.\", ex); }","preventionTips":["Use the same ToJsonProperty name for partition key properties across a shared container.","Avoid renaming only one type's partition key JSON property.","Validate store-name consistency in a model convention."],"tags":["cosmos","partition-key","json-mapping","shared-container","model-validation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}