{"record":{"id":"357fecddf71ab564","repo":"dotnet/efcore","slug":"both-properties-property1-and-property2-on","errorCode":null,"errorMessage":"Both properties '{property1}' and '{property2}' on entity type '{entityType}' are mapped to '{storeName}'. Map one of the properties to a different JSON property.","messagePattern":"Both properties '(.+?)' and '(.+?)' on entity type '(.+?)' are mapped to '(.+?)'\\. Map one of the properties to a different JSON property\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs","lineNumber":521,"sourceCode":"\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    protected virtual void ValidateDatabaseProperties(\n        IEntityType entityType,\n        IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)\n    {\n        var properties = new Dictionary<string, IPropertyBase>();\n        foreach (var property in entityType.GetProperties().Where(x => x.IsPersisted()))\n        {\n            var jsonName = property.GetJsonPropertyName();\n\n            if (properties.TryGetValue(jsonName, out var otherProperty))\n            {\n                throw new InvalidOperationException(\n                    CosmosStrings.JsonPropertyCollision(property.Name, otherProperty.Name, entityType.DisplayName(), jsonName));\n            }\n\n            properties[jsonName] = property;\n        }\n\n        foreach (var navigation in entityType.GetNavigations())\n        {\n            if (!navigation.IsEmbedded())\n            {\n                continue;\n            }\n\n            var jsonName = navigation.TargetEntityType.GetContainingPropertyName()!;\n            if (properties.TryGetValue(jsonName, out var otherProperty))\n            {\n                throw new InvalidOperationException(\n                    CosmosStrings.JsonPropertyCollision(navigation.Name, otherProperty.Name, entityType.DisplayName(), jsonName));","sourceCodeStart":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs#L503-L539","documentation":"Thrown when two PERSISTED properties on the same entity type map to the same JSON property name. Cosmos documents are JSON objects, so each property under an entity must have a unique JSON name. The validator builds a dictionary keyed by the resolved JSON name and throws on the first collision between two scalar properties.","triggerScenarios":"Two properties whose ToJsonProperty target resolves to the same string (e.g. both default to \"Name\" after a rename, or two properties explicitly mapped to \"id\" / same JSON path). Fires during ValidateDatabaseProperties for every entity.","commonSituations":"Renaming a CLR property but forgetting to update a manual ToJsonProperty call so it now collides with another; inheriting a base property and re-declaring a same-named one on the derived type with the same JSON mapping; mapping both a shadow property and a real property to the same JSON path.","solutions":["Give each property a distinct JSON name via ToJsonProperty(\"uniqueName\").","Identify the two property names in the error message and search the model config for both, then fix the duplicated target.","If one is a leftover shadow property, remove it instead of renaming.","If a base-type property and a derived property collide, override the JSON name on the derived one."],"exampleFix":"// before\nmodelBuilder.Entity<User>().Property(u => u.FirstName).ToJsonProperty(\"Name\");\nmodelBuilder.Entity<User>().Property(u => u.LastName).ToJsonProperty(\"Name\");\n\n// after\nmodelBuilder.Entity<User>().Property(u => u.FirstName).ToJsonProperty(\"Name\");\nmodelBuilder.Entity<User>().Property(u => u.LastName).ToJsonProperty(\"Surname\");","handlingStrategy":"validation","validationCode":"foreach (var et in dbContext.Model.GetEntityTypes())\n{\n    var seen = new HashSet<string>();\n    foreach (var p in et.GetProperties().Where(x => x.IsPersisted()))\n    {\n        var json = p.GetJsonPropertyName();\n        if (!seen.Add(json)) throw new InvalidOperationException($\"JSON name {json} collision on {et.DisplayName()}\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use distinct ToJsonProperty names; consider letting the convention pick them automatically.","After renaming a CLR property, audit any manual ToJsonProperty calls.","Add a unit test that asserts no persisted property JSON collisions."],"tags":["cosmos","model-validation","json-mapping","property","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}