{"record":{"id":"0655c094be404b1c","repo":"dotnet/efcore","slug":"entity-type-entitytype-has-a-split-mapping-for-0655c0","errorCode":null,"errorMessage":"Entity type '{entityType}' has a split mapping for '{storeObject}' that is shared with the entity type '{principalEntityType}', but the main mappings of these types do not share a table. Map the split fragments of '{entityType}' to non-shared tables or map the main fragment to '{principalStoreObject}'.","messagePattern":"Entity type '(.+?)' has a split mapping for '(.+?)' that is shared with the entity type '(.+?)', but the main mappings of these types do not share a table\\. Map the split fragments of '(.+?)' to non-shared tables or map the main fragment to '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":2407,"sourceCode":"                throw new InvalidOperationException(\n                    RelationalStrings.EntitySplittingUnmappedMainFragment(\n                        entityType.DisplayName(), fragment.StoreObject.DisplayName(), fragment.StoreObject.StoreObjectType));\n            }\n\n            if (fragment.StoreObject == mainStoreObject)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.EntitySplittingConflictingMainFragment(\n                        entityType.DisplayName(), fragment.StoreObject.DisplayName()));\n            }\n\n            foreach (var foreignKey in entityType.FindRowInternalForeignKeys(fragment.StoreObject))\n            {\n                var principalMainFragment = StoreObjectIdentifier.Create(\n                    foreignKey.PrincipalEntityType, fragment.StoreObject.StoreObjectType)!.Value;\n                if (principalMainFragment != mainStoreObject)\n                {\n                    throw new InvalidOperationException(\n                        RelationalStrings.EntitySplittingUnmatchedMainTableSplitting(\n                            entityType.DisplayName(),\n                            fragment.StoreObject.DisplayName(),\n                            foreignKey.PrincipalEntityType.DisplayName(),\n                            principalMainFragment.DisplayName()));\n                }\n            }\n\n            var propertiesFound = false;\n            foreach (var property in entityType.GetProperties())\n            {\n                var columnName = property.GetColumnName(fragment.StoreObject);\n                if (columnName == null)\n                {\n                    if (property.IsPrimaryKey())\n                    {\n                        throw new InvalidOperationException(\n                            RelationalStrings.EntitySplittingMissingPrimaryKey(","sourceCodeStart":2389,"sourceCodeEnd":2425,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2389-L2425","documentation":"Thrown in the entity-splitting validator when a split fragment of an entity shares its table with a principal entity (via a row internal foreign key, i.e. table splitting between two entities), but the main mappings of those two entities do not themselves share a table. The split fragment's principal main store object (StoreObjectIdentifier.Create of the principal for the same store-object type) differs from the dependent's mainStoreObject, so the relationship is inconsistent.","triggerScenarios":"An entity Customer is table-split with AuditInfo (AuditInfo has a row internal FK to Customer on the split fragment), but AuditInfo's main ToTable points somewhere different than Customer's main table, so the principalMainFragment != mainStoreObject for the fragment.","commonSituations":"Mixing entity splitting (SplitToTable) with owned/table-split types whose main tables drift apart; refactor that changed a principal's main table without updating the dependent's split fragment; inconsistent ToTable across an ownership.","solutions":["Align the principal's main mapping to the dependent's main table so the split fragment is shared consistently: ToTable the principal to the same store object.","Or map the dependent's split fragments to non-shared tables (remove the row-internal-FK sharing on that fragment).","Make the ownership/table-splitting consistent across both the main and split mappings."],"exampleFix":"// before\nmodelBuilder.Entity<Customer>().ToTable(\"Customers\");\nmodelBuilder.Entity<Customer>()\n    .OwnsOne(c => c.Audit, a => a.ToTable(\"Customers\")) // shares via row IFK\n    .SplitToTable(\"CustomerExtras\", t => t.Property(c => c.Notes));\n// but principal main table differs -> throws 439\n\n// after - keep principal main table aligned\nmodelBuilder.Entity<Customer>().ToTable(\"Customers\");\nmodelBuilder.Entity<Customer>().OwnsOne(c => c.Audit, a => a.ToTable(\"Customers\"));\n// do not split a fragment that shares a table unless main tables also share","handlingStrategy":"validation","validationCode":"foreach (var entityType in modelBuilder.Model.GetEntityTypes())\n{\n    var fragments = EntityTypeMappingFragment.Get(entityType);\n    if (fragments == null) continue;\n    foreach (var fragment in fragments)\n    {\n        var main = StoreObjectIdentifier.Create(entityType, fragment.StoreObject.StoreObjectType);\n        if (main == null) continue;\n        foreach (var fk in entityType.FindRowInternalForeignKeys(fragment.StoreObject))\n        {\n            var principalMain = StoreObjectIdentifier.Create(fk.PrincipalEntityType, fragment.StoreObject.StoreObjectType);\n            if (principalMain != null && principalMain.Value != main.Value)\n                throw new InvalidOperationException($\"{entityType.DisplayName()} split fragment {fragment.StoreObject.DisplayName()} shares a table with {fk.PrincipalEntityType.DisplayName()} but main mappings differ ({main.Value.DisplayName()} vs {principalMain.Value.DisplayName()}).\");\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When using SplitToTable together with owned/table-split types, keep the principal's main table aligned with the dependent's main table.","After changing a principal's ToTable, audit dependent split fragments for consistency.","Add a model test that validates split fragments against row-internal-FK principals."],"tags":["ef-core","model-validation","mapping","table-splitting","owned-types"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}