{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L1491-L1527","documentation":"Two properties declared within the same inheritance hierarchy (one type is assignable from the other) cannot map to the same column on the same store object, because EF would not know which property a column value belongs to and the generated SQL/migrations would conflict. The validator at line 1506-1517 throws DuplicateColumnNameSameHierarchy when the duplicate column is found and the two declaring types are in the same hierarchy (the IsAssignableFrom checks succeed).","triggerScenarios":"In a TPH hierarchy, two sibling or ancestor/descendant entity types each declare a property that maps to the same column name on the same table. Triggered during ValidateSharedColumnsCompatibility's property-mapping walk.","commonSituations":"Two derived types accidentally using the same column name (e.g. both have a 'Notes' property); a base type property and a derived type property colliding after a rename; complex type properties whose names collide with owner properties.","solutions":["Rename one of the properties' column via .HasColumnName(\"<distinct>\") so they no longer collide.","If the column is meant to be shared, hoist the property up to the common base type so a single declared property maps to it.","Remove the duplicate property if it is redundant."],"exampleFix":"// before: BaseShape and derived Circle both have a property mapped to 'Radius'\n//         on the same TPH table 'Shapes'\nmodelBuilder.Entity<BaseShape>().Property(b => b.Size).HasColumnName(\"Radius\");\nmodelBuilder.Entity<Circle>().Property(c => c.Radius).HasColumnName(\"Radius\");\n\n// after\nmodelBuilder.Entity<BaseShape>().Property(b => b.Size).HasColumnName(\"Size\");\nmodelBuilder.Entity<Circle>().Property(c => c.Radius).HasColumnName(\"Radius\");","handlingStrategy":"validation","validationCode":"foreach (var et in modelBuilder.Model.GetEntityTypes())\n{\n    var table = et.GetTableName();\n    if (table == null) continue;\n    var storeObj = StoreObjectIdentifier.Table(table, et.GetSchema());\n    var colToTypes = new Dictionary<string, List<(IProperty P, ITypeBase Decl)>>();\n    foreach (var type in modelBuilder.Model.GetEntityTypes().Where(e => e.GetTableName() == table))\n    {\n        foreach (var p in type.GetProperties())\n        {\n            var col = p.GetColumnName(storeObj);\n            if (col == null) continue;\n            if (!colToTypes.ContainsKey(col)) colToTypes[col] = new();\n            colToTypes[col].Add((p, p.DeclaringType));\n        }\n    }\n    foreach (var (col, list) in colToTypes)\n    {\n        for (int i = 0; i < list.Count; i++)\n            for (int j = i + 1; j < list.Count; j++)\n            {\n                var a = list[i]; var b = list[j];\n                if (a.Decl.IsAssignableFrom(b.Decl) || b.Decl.IsAssignableFrom(a.Decl))\n                    throw new InvalidOperationException(\n                        $\"Column '{col}' on table '{table}' mapped by two properties in same hierarchy: \"\n                        + $\"{a.P.DeclaringType.DisplayName()}.{a.P.Name} and {b.P.DeclaringType.DisplayName()}.{b.P.Name}\");\n            }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In TPH hierarchies, ensure each declared property maps to a distinct column name via .HasColumnName(...).","If a column is shared semantically, hoist the property to the common base type instead of declaring it twice.","Add a test that no two properties in the same hierarchy collide on column name within a table."],"tags":["ef-core","table-sharing","inheritance","model-validation","columns"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}