{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs#L503-L539","documentation":"Thrown by ValidateDatabaseProperties when two persisted properties on the same entity type map to the same JSON property name (GetJsonPropertyName). Cosmos stores entities as JSON, so two CLR properties collapsing to one JSON name would silently overwrite each other; the validator surfaces this at model validation.","triggerScenarios":"Two properties whose default or ToJsonProperty-configured names coincide, e.g. Id and id differing only by casing collapsing to the same name, or explicitly mapping two properties to the same ToJsonProperty value.","commonSituations":"Case-insensitive name collisions (e.g. 'Id'/'id'); renaming via ToJsonProperty to a value already used; inherited properties colliding with declared ones.","solutions":["Give each property a distinct ToJsonProperty value.","Rename one of the conflicting CLR properties or exclude one from persistence (IsPersisted(false)/not mapped).","Audit JSON names when introducing a new property to an existing entity."],"exampleFix":"// before\nmodelBuilder.Entity<User>()\n    .Property(u => u.Id).ToJsonProperty(\"name\");\nmodelBuilder.Entity<User>()\n    .Property(u => u.DisplayName).ToJsonProperty(\"name\");\n\n// after\nmodelBuilder.Entity<User>()\n    .Property(u => u.Id).ToJsonProperty(\"id\");\nmodelBuilder.Entity<User>()\n    .Property(u => u.DisplayName).ToJsonProperty(\"name\");","handlingStrategy":"validation","validationCode":"using var ctx = new MyContext();\nforeach (var e in ctx.Model.GetEntityTypes())\n{\n    var names = e.GetProperties().Where(p => p.IsPersisted()).Select(p => p.GetJsonPropertyName()).ToList();\n    Debug.Assert(names.Count == names.Distinct().Count(), $\"{e.Name} has colliding JSON property names\");\n}","typeGuard":null,"tryCatchPattern":"try { ctx.Model.GetModel(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"are mapped to\") && ex.Message.Contains(\"JSON property\"))\n{\n    logger.LogError(ex, \"Two properties collide on the same JSON name\");\n    throw;\n}","preventionTips":["Audit ToJsonProperty values whenever adding or renaming a property.","Avoid name pairs that differ only by case, which can collapse in JSON.","Add a test asserting all persisted JSON names per entity are distinct."],"tags":["cosmos","configuration","model-validation","json-mapping","property"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}