{"record":{"id":"ba43f451777a9655","repo":"dotnet/efcore","slug":"entitytype1-property1-and-entitytype2-pr","errorCode":null,"errorMessage":"'{entityType1}.{property1}' and '{entityType2}.{property2}' are both mapped to column '{columnName}' in '{table}', but the properties are contained within the same hierarchy. All properties on an entity type must be mapped to different columns.","messagePattern":"'(.+?)\\.(.+?)' and '(.+?)\\.(.+?)' are both mapped to column '(.+?)' in '(.+?)', but the properties are contained within the same hierarchy\\. All properties on an entity type must be mapped to different columns\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":1509,"sourceCode":"            foreach (var property in structuralType.GetDeclaredProperties())\n            {\n                var columnName = property.GetColumnName(storeObject);\n                if (columnName == null)\n                {\n                    continue;\n                }\n\n                missingConcurrencyTokens?.Remove(columnName);\n                if (!propertyMappings.TryGetValue(columnName, out var duplicateProperty))\n                {\n                    propertyMappings[columnName] = property;\n                    continue;\n                }\n\n                if (property.DeclaringType.IsAssignableFrom(duplicateProperty.DeclaringType)\n                    || duplicateProperty.DeclaringType.IsAssignableFrom(property.DeclaringType))\n                {\n                    throw new InvalidOperationException(\n                        RelationalStrings.DuplicateColumnNameSameHierarchy(\n                            duplicateProperty.DeclaringType.DisplayName(),\n                            duplicateProperty.Name,\n                            property.DeclaringType.DisplayName(),\n                            property.Name,\n                            columnName,\n                            storeObject.DisplayName()));\n                }\n\n                this.ValidateCompatible(property, duplicateProperty, columnName, storeObject, logger);\n            }\n\n            foreach (var complexProperty in structuralType.GetDeclaredComplexProperties())\n            {\n                ValidateCompatible(complexProperty.ComplexType, storeObject, propertyMappings, missingConcurrencyTokens, logger);\n            }\n        }\n    }","sourceCodeStart":1491,"sourceCodeEnd":1527,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L1491-L1527","documentation":"Two properties that live in the same inheritance hierarchy were mapped to the same column on a table/view. Within a single hierarchy, EF requires every property to map to a distinct column because the framework treats the column set as the union of all derived types' properties and cannot resolve ambiguity. The IsAssignableFrom check between the two declaring types confirms they are in one hierarchy (sibling/derived).","triggerScenarios":"An inheritance hierarchy (TPH/TPT) where two sibling derived types both have a property with the same HasColumnName, or a base and derived type each declare a property mapped to the same column name. Thrown in ValidateSharedColumnsCompatibility when property.DeclaringType.IsAssignableFrom(duplicateProperty.DeclaringType) or vice versa.","commonSituations":"Two derived entities (e.g. Manager and Employee) both having a 'Name' column with HasColumnName(\"Name\"); renaming a property but not its column; merging two hierarchies that previously had separate tables into one TPH table.","solutions":["Rename one of the properties' column via HasColumnName(\"<unique-name>\") so they no longer collide.","Consolidate the two properties into a single property declared on the common base type.","If they genuinely represent the same value, map them to one property on the base type instead of two.","Switch the conflicting derived types to TPT/TPC so they live in separate tables."],"exampleFix":"// before\nmodelBuilder.Entity<Manager>().Property(m => m.DepartmentName).HasColumnName(\"Name\");\nmodelBuilder.Entity<Engineer>().Property(e => e.ProjectName).HasColumnName(\"Name\"); // same hierarchy\n\n// after\nmodelBuilder.Entity<Manager>().Property(m => m.DepartmentName).HasColumnName(\"DepartmentName\");\nmodelBuilder.Entity<Engineer>().Property(e => e.ProjectName).HasColumnName(\"ProjectName\");","handlingStrategy":"validation","validationCode":"// Detect properties in one hierarchy mapped to the same column.\nvar groups = hierarchyTypes.SelectMany(t => t.GetProperties())\n    .Where(p => p.GetColumnName(storeObject) is string c)\n    .GroupBy(p => p.GetColumnName(storeObject)!)\n    .Where(g => g.Count() > 1\n        && g.Select(p => p.DeclaringType).Distinct().Any(d1 => g.Any(p2 => p2.DeclaringType != d1 && (d1.IsAssignableFrom(p2.DeclaringType) || p2.DeclaringType.IsAssignableFrom(d1)))));\nforeach (var g in groups) Console.WriteLine($\"Conflict on column {g.Key}\");","typeGuard":null,"tryCatchPattern":"try { _ = db.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains(\"contained within the same hierarchy\")) { // rename one of the conflicting columns }","preventionTips":["Never call HasColumnName with the same value on properties declared in different branches of a hierarchy.","Use a naming convention derived from the type+property to avoid accidental collisions.","Review column names when merging two previously-separate hierarchies."],"tags":["model-validation","column-mapping","inheritance","relational"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}