{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2389-L2425","documentation":"When a split fragment is shared with a principal entity via a row-internal foreign key, ValidateMappingFragment checks that the MAIN mappings of the dependent and principal share the same table. If principalMainFragment != mainStoreObject (the dependent's main table), the split is inconsistent with how the entities are otherwise mapped, and EF throws.","triggerScenarios":"An entity has a split fragment, and on that fragment there is a row-internal FK whose principal's main store object (same StoreObjectType) differs from the dependent's main store object. Happens when a split fragment reuses a principal's table but the dependent's main table is something else.","commonSituations":"Table splitting where the dependent's extra fragment points at the principal's table while the dependent's own main table is unrelated; refactoring shared tables without updating both main and split mappings.","solutions":["Map the dependent's split fragments to non-shared (independent) tables so they do not rely on the principal's table.","Realign the dependent's main mapping onto the principal's store object (principalMainFragment) so main and split agree.","Remove the row-internal FK / shared-table relationship that introduced the inconsistency."],"exampleFix":"// before\nmodelBuilder.Entity<Order>().ToTable(\"Orders\");\nmodelBuilder.Entity<Order>().OwnsOne(o => o.Detail, d => d.ToTable(\"Orders\")); // detail main shared\nmodelBuilder.Entity<Order>().SplitToTable(\"OrderExtras\", t => t.Property(...));\n// principal main ('Orders') != dependent main when split expects shared\n\n// after (align main fragment to principal table)\nmodelBuilder.Entity<Order>().OwnsOne(o => o.Detail, d => d.ToTable(\"Orders\"));\nmodelBuilder.Entity<Order>().ToTable(\"Orders\"); // main matches the shared principal table","handlingStrategy":"validation","validationCode":"bool SplitFragmentsAlignWithPrincipalMain(DbContext context)\n{\n    foreach (var et in context.Model.GetEntityTypes())\n    foreach (var f in et.GetTableMappingFragments())\n    {\n        var main = StoreObjectIdentifier.Create(et, StoreObjectType.Table);\n        if (main is null) continue;\n        foreach (var fk in et.FindRowInternalForeignKeys(f.StoreObject))\n        {\n            var principalMain = StoreObjectIdentifier.Create(fk.PrincipalEntityType, StoreObjectType.Table);\n            if (principalMain is not null && principalMain != main) return false;\n        }\n    }\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try { _ = context.Model; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"split mapping\", StringComparison.Ordinal) && ex.Message.Contains(\"do not share a table\", StringComparison.Ordinal))\n{\n    throw new InvalidOperationException(\"A split fragment shares a principal's table but main mappings differ. Align the dependent's main table with the principal's, or move the fragment off the shared table.\", ex);\n}","preventionTips":["When table-splitting, keep the dependent's main table equal to the principal's main table.","Avoid pointing split fragments at a principal's table unless main mappings also match.","Test the model build after introducing shared-table relationships."],"tags":["ef-core","model-validation","entity-splitting","table-splitting","owned-types","relational"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}