{"record":{"id":"24e92b3cf840fc42","repo":"dotnet/efcore","slug":"entity-type-entitytype-has-a-split-mapping-for","errorCode":null,"errorMessage":"Entity type '{entityType}' has a split mapping for '{storeObject}', but it also participates in an entity type hierarchy. Split mappings are not supported for hierarchies.","messagePattern":"Entity type '(.+?)' has a split mapping for '(.+?)', but it also participates in an entity type hierarchy\\. Split mappings are not supported for hierarchies\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":2378,"sourceCode":"    /// <summary>\n    ///     Validates the mapping fragments for an entity type.\n    /// </summary>\n    /// <param name=\"entityType\">The entity type to validate.</param>\n    /// <param name=\"logger\">The logger to use.</param>\n    protected virtual void ValidateMappingFragment(\n        IEntityType entityType,\n        IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)\n    {\n        var fragments = EntityTypeMappingFragment.Get(entityType);\n        if (fragments == null)\n        {\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(","sourceCodeStart":2360,"sourceCodeEnd":2396,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2360-L2396","documentation":"ValidateMappingFragment refuses entity splitting (.SplitToTable / EntityTypeMappingFragment) for any entity that participates in an inheritance hierarchy, whether it has a BaseType or has directly derived types. Splitting fragments across a hierarchy is unsupported because EF cannot reconcile per-fragment row-internal FKs with inheritance mapping, so it throws on the first fragment.","triggerScenarios":"An entity type has at least one EntityTypeMappingFragment (created by .SplitToTable(...)) AND (entityType.BaseType != null OR entityType.GetDirectlyDerivedTypes().Any()). Reported with the first fragment's store object name.","commonSituations":"Applying entity splitting (a common optimization for wide tables) to a base or derived entity that is later added to an inheritance chain; scaffolding splits then introducing a hierarchy; refactoring a flat entity into a base class while keeping its SplitToTable calls.","solutions":["Remove .SplitToTable calls from any entity that has a base or derived type; keep all its properties in the main table.","If you need horizontal decomposition, model it as owned types or one-to-one relationships instead of entity splitting.","Pull the split entity out of the hierarchy (remove HasBaseType) so splitting becomes legal."],"exampleFix":"// before\nmodelBuilder.Entity<Customer>().HasBaseType<Person>()\n    .SplitToTable(\"CustomerExtras\", t => t.Property(c => c.Notes));\n\n// after\nmodelBuilder.Entity<Customer>().HasBaseType<Person>();\n// move Notes into an owned type or a separate 1:1 entity instead of a split fragment","handlingStrategy":"validation","validationCode":"bool NoSplittingInHierarchies(DbContext context)\n{\n    foreach (var et in context.Model.GetEntityTypes())\n    {\n        if (!et.GetTableMappingFragments().Any() && !et.GetViewMappingFragments().Any()) continue;\n        if (et.BaseType != null || et.GetDirectlyDerivedTypes().Any()) 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(\"hierarchy\", StringComparison.Ordinal))\n{\n    throw new InvalidOperationException(\"Entity splitting is not supported inside an inheritance hierarchy. Remove .SplitToTable or use owned types instead.\", ex);\n}","preventionTips":["Never call .SplitToTable on a base or derived entity type.","Prefer owned types or 1:1 entities for horizontal decomposition within hierarchies.","Add a model test asserting no hierarchy member has mapping fragments."],"tags":["ef-core","model-validation","entity-splitting","inheritance","relational"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}