{"record":{"id":"bd285f933f93c72d","repo":"dotnet/efcore","slug":"entity-type-entitytype-has-a-split-mapping-for-bd285f","errorCode":null,"errorMessage":"Entity type '{entityType}' has a split mapping for '{storeObject}', but the primary key properties aren't fully mapped. Map all primary key properties to columns on '{storeObject}'.","messagePattern":"Entity type '(.+?)' has a split mapping for '(.+?)', but the primary key properties aren't fully mapped\\. Map all primary key properties to columns on '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":2424,"sourceCode":"                {\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(\n                                entityType.DisplayName(), fragment.StoreObject.DisplayName()));\n                    }\n\n                    continue;\n                }\n\n                if (!property.IsPrimaryKey())\n                {\n                    propertiesFound = true;\n                }\n            }\n\n            if (!propertiesFound)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.EntitySplittingMissingProperties(\n                        entityType.DisplayName(), fragment.StoreObject.DisplayName()));","sourceCodeStart":2406,"sourceCodeEnd":2442,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2406-L2442","documentation":"Entity splitting spreads one entity across several tables via SplitToTable/SplitToView fragments. The relational model validator walks each fragment and resolves a column name for every property; if a PRIMARY KEY property resolves to no column on a fragment, it throws, because the fragment cannot link its rows back to the entity without the full key. All key columns must be present on every split fragment.","triggerScenarios":"Calling entityTypeBuilder.SplitToTable(\"Extra\") (or SplitToView / a MappingFragment) and then unmapping or renaming a key property on that fragment, e.g. property.HasColumnName(null, \"Extra\") on an Id property, or a table-specific override that drops the key column. Also triggered when a key convention is suppressed so GetColumnName(fragment.StoreObject) returns null for a key property.","commonSituations":"Copying a SplitToTable block and forgetting to map the key; using table-specific column overrides (.HasColumnName(name, name: \"Extra\")) that accidentally exclude the PK; renaming fragments; upgrading EF and a previously-tolerated mapping now fails validation.","solutions":["Ensure every primary key property has a column on the offending fragment: property.HasColumnName(\"Id\", \"ExtraFragmentName\").","Remove any table-specific override (.HasColumnName(null, fragment)) that is suppressing a key column on the fragment.","If the fragment cannot carry the full key, drop the fragment and model the extra columns differently (owned type, one-to-one, or TPH).","Verify the entity's key is not shadow/composite-with-unmapped-part that never reaches the fragment."],"exampleFix":"// before\nmodelBuilder.Entity<Customer>()\n    .SplitToTable(\"CustomerExtra\", tb =>\n    {\n        tb.Property(c => c.Notes).HasColumnName(\"Notes\");\n        // Id not mapped -> [440]\n    });\n\n// after\nmodelBuilder.Entity<Customer>()\n    .SplitToTable(\"CustomerExtra\", tb =>\n    {\n        tb.Property(c => c.Id).HasColumnName(\"Id\");\n        tb.Property(c => c.Notes).HasColumnName(\"Notes\");\n    });","handlingStrategy":"validation","validationCode":"// Before relying on the model, verify every key property has a column on each split fragment.\nforeach (var fragment in entityType.GetTableMappings().SelectMany(t => t.EntityTypeMappings).SelectMany(m => m.TableMappings is null ? Array.Empty<object>() : Array.Empty<object>())) { /* placeholder */ }\n\n// Simpler: assert key coverage per fragment store object.\nvar fragments = entityType.GetFragmentMappings(); // or your mapping accessor\nforeach (var fragment in entityType.GetMappingFragments())\n{\n    foreach (var keyProp in entityType.FindPrimaryKey()!.Properties)\n    {\n        if (keyProp.GetColumnName(fragment.StoreObject) is null)\n            throw new InvalidOperationException($\"Key property {keyProp.Name} is unmapped on fragment {fragment.StoreObject.DisplayName()}.\");\n    }\n}","typeGuard":"// Guard before adding a split fragment.\nstatic bool IsKeyFullyMappedOnFragment(IEntityType et, StoreObjectIdentifier store)\n    => et.FindPrimaryKey()!.Properties.All(p => p.GetColumnName(store) is not null);","tryCatchPattern":null,"preventionTips":["Centralize split-mapping setup in one place and assert key coverage per fragment after configuration.","Never null-out a key column with .HasColumnName(null, fragment).","Write a model-snapshot test that builds the model and exercises the validator to catch this at test time."],"tags":["entity-splitting","model-validation","primary-key","relational"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}