{"record":{"id":"5200e97b202c118d","repo":"dotnet/efcore","slug":"entity-type-entitytype-has-a-split-mapping-for-5200e9","errorCode":null,"errorMessage":"Entity type '{entityType}' has a split mapping for '{storeObject}', but it doesn't have a main mapping of the same type. Map '{entityType}' to '{storeObjectType}'.","messagePattern":"Entity type '(.+?)' has a split mapping for '(.+?)', but it doesn't have a main mapping of the same type\\. Map '(.+?)' to '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":2389,"sourceCode":"        {\n            return;\n        }\n\n        if (entityType.BaseType != null\n            || entityType.GetDirectlyDerivedTypes().Any())\n        {\n            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(","sourceCodeStart":2371,"sourceCodeEnd":2407,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2371-L2407","documentation":"ValidateMappingFragment requires that for every split fragment, the entity has a MAIN mapping of the same store object type. If you call .SplitToTable(\"Extras\", ...) but the entity is not itself mapped to a table (StoreObjectIdentifier.Create(entity, Table) returns null), EF has nothing to split FROM and throws, naming the fragment and the missing store object type.","triggerScenarios":"An EntityTypeMappingFragment exists for StoreObjectType.Table (or View), but StoreObjectIdentifier.Create(entityType, fragment.StoreObject.StoreObjectType) is null because the entity was mapped ToView-only (or not at all) while split fragments targeted tables, or vice versa for views.","commonSituations":"Calling .SplitToTable on an entity that is query-only via .ToView and has no table; mixing .ToView with .SplitToTable without an explicit ToTable; scaffolding splits for a view-mapped entity.","solutions":["Add the matching main mapping: modelBuilder.Entity<E>().ToTable(\"E\") before .SplitToTable(...).","If splitting a view, also map the main object as a view via .ToView(\"main\").","Remove the split fragment whose store object type has no corresponding main mapping."],"exampleFix":"// before\nmodelBuilder.Entity<Customer>().ToView(\"v_Customer\")\n    .SplitToTable(\"CustomerExtras\", t => t.Property(c => c.Notes)); // no main table\n\n// after\nmodelBuilder.Entity<Customer>().ToTable(\"Customers\")\n    .SplitToTable(\"CustomerExtras\", t => t.Property(c => c.Notes));","handlingStrategy":"validation","validationCode":"bool SplitFragmentsHaveMainMapping(DbContext context)\n{\n    foreach (var et in context.Model.GetEntityTypes())\n    {\n        foreach (var f in et.GetTableMappingFragments())\n            if (StoreObjectIdentifier.Create(et, StoreObjectType.Table) is null) return false;\n        foreach (var f in et.GetViewMappingFragments())\n            if (StoreObjectIdentifier.Create(et, StoreObjectType.View) is null) return false;\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(\"main mapping\", StringComparison.Ordinal))\n{\n    throw new InvalidOperationException(\"A split fragment needs a main mapping of the same store object type. Add ToTable/ToView to the entity.\", ex);\n}","preventionTips":["Always pair .SplitToTable with an explicit .ToTable on the same entity (and .SplitToView with .ToView).","Avoid mapping an entity ToView-only and then splitting it to tables.","Validate the model in tests after configuring splits."],"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"}