{"record":{"id":"4252d336c6d3d739","repo":"dotnet/efcore","slug":"entity-type-entitytype-has-a-split-mapping-for-4252d3","errorCode":null,"errorMessage":"Entity type '{entityType}' has a split mapping for '{storeObject}', but is it also mapped to the same object. Split mappings should not duplicate the main mapping.","messagePattern":"Entity type '(.+?)' has a split mapping for '(.+?)', but is it also mapped to the same object\\. Split mappings should not duplicate the main mapping\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":2396,"sourceCode":"            throw new InvalidOperationException(\n                RelationalStrings.EntitySplittingHierarchy(entityType.DisplayName(), fragments.First().StoreObject.DisplayName()));\n        }\n\n        var anyTableFragments = false;\n        var anyViewFragments = false;\n        foreach (var fragment in fragments)\n        {\n            var mainStoreObject = StoreObjectIdentifier.Create(entityType, fragment.StoreObject.StoreObjectType);\n            if (mainStoreObject == null)\n            {\n                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            }","sourceCodeStart":2378,"sourceCodeEnd":2414,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2378-L2414","documentation":"A split fragment's StoreObjectIdentifier must NOT equal the entity's main mapping store object for the same type; splitting is for ADDITIONAL store objects beyond the main one. ValidateMappingFragment throws when fragment.StoreObject == mainStoreObject, i.e. you told EF to split a table into itself.","triggerScenarios":"Calling .SplitToTable(\"Customers\", ...) on an entity whose main table is ALSO \"Customers\" (same name and schema), so the fragment store object equals the main. The equality check fragment.StoreObject == mainStoreObject fails.","commonSituations":"Copy-pasting the main table name into a SplitToTable call; scaffolding splits and forgetting to rename; refactoring that left a fragment pointing back at the primary table.","solutions":["Rename the split fragment's table to a different physical table: .SplitToTable(\"CustomerExtras\", ...).","Remove the redundant fragment that duplicates the main mapping.","If you intended to move all properties to one table, drop splitting entirely and use the main ToTable."],"exampleFix":"// before\nmodelBuilder.Entity<Customer>().ToTable(\"Customers\")\n    .SplitToTable(\"Customers\", t => t.Property(c => c.Notes)); // same as main\n\n// after\nmodelBuilder.Entity<Customer>().ToTable(\"Customers\")\n    .SplitToTable(\"CustomerExtras\", t => t.Property(c => c.Notes));","handlingStrategy":"validation","validationCode":"bool SplitFragmentsDifferFromMain(DbContext context)\n{\n    foreach (var et in context.Model.GetEntityTypes())\n    {\n        foreach (var f in et.GetTableMappingFragments())\n        {\n            var main = StoreObjectIdentifier.Create(et, StoreObjectType.Table);\n            if (main is null) continue;\n            if (f.StoreObject == 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(\"duplicate the main mapping\", StringComparison.Ordinal))\n{\n    throw new InvalidOperationException(\"A split fragment must not reuse the entity's main table. Rename the fragment table or remove it.\", ex);\n}","preventionTips":["Use a distinct table name in every .SplitToTable call; never copy the main ToTable name.","Review scaffolded splits to ensure fragment names differ from the main table.","Add a test that asserts fragment store objects differ from the main store object."],"tags":["ef-core","model-validation","entity-splitting","relational"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}