{"record":{"id":"7213f48adfb20a7d","repo":"dotnet/efcore","slug":"the-derived-entity-type-entitytype-was-configu","errorCode":null,"errorMessage":"The derived entity type '{entityType}' was configured with the '{strategy}' mapping strategy. Only the root entity type should be configured with a mapping strategy. See https://go.microsoft.com/fwlink/?linkid=2130430 for more information.","messagePattern":"The derived entity type '(.+?)' was configured with the '(.+?)' mapping strategy\\. Only the root entity type should be configured with a mapping strategy\\. See https://go\\.microsoft\\.com/fwlink/\\?linkid=2130430 for more information\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":2090,"sourceCode":"                ?? entityType.GetSqlQuery()\n                ?? entityType.GetInsertStoredProcedure()?.GetSchemaQualifiedName()\n                ?? entityType.GetDeleteStoredProcedure()?.GetSchemaQualifiedName()\n                ?? entityType.GetUpdateStoredProcedure()?.GetSchemaQualifiedName();\n            if (mappingStrategy == RelationalAnnotationNames.TpcMappingStrategy\n                && !entityType.ClrType.IsInstantiable()\n                && storeObjectName != null)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.AbstractTpc(entityType.DisplayName(), storeObjectName));\n            }\n        }\n\n        if (entityType.BaseType != null)\n        {\n            if (mappingStrategy != null\n                && mappingStrategy != (string?)entityType.BaseType[RelationalAnnotationNames.MappingStrategy])\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.DerivedStrategy(entityType.DisplayName(), mappingStrategy));\n            }\n\n            return;\n        }\n\n        // Hierarchy mapping strategy must be the same across all types of mappings (only for root types)\n        if (entityType.FindDiscriminatorProperty() != null)\n        {\n            if (mappingStrategy is not null\n                and not RelationalAnnotationNames.TphMappingStrategy)\n            {\n                throw new InvalidOperationException(\n                    RelationalStrings.NonTphMappingStrategy(mappingStrategy, entityType.DisplayName()));\n            }\n\n            ValidateTphMapping(entityType, StoreObjectType.Table);\n            ValidateTphMapping(entityType, StoreObjectType.View);","sourceCodeStart":2072,"sourceCodeEnd":2108,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2072-L2108","documentation":"A derived entity type (one with a BaseType) was explicitly configured with a mapping strategy (TPH/TPT/TPC) that differs from its base type's strategy. Mapping strategy must be set only on the root of the hierarchy and applies to the whole hierarchy. Thrown from ValidateInheritanceMapping when entityType.BaseType != null and the strategy differs from the base.","triggerScenarios":"Calling modelBuilder.Entity<Derived>().UseTptMappingStrategy() while the root has UseTphMappingStrategy() (or no strategy); accidentally applying [UseTpcMappingStrategy] attribute or ToTable(t) calls that imply a strategy on a derived type.","commonSituations":"Reading outdated docs that suggested setting strategy per type; copy-pasting root configuration to derived entities; refactoring a hierarchy and forgetting to remove strategy calls on children.","solutions":["Remove the strategy call from the derived entity; set the strategy once on the root type.","Ensure any strategy-implicating calls (ToTable per derived type for TPT) are applied consistently from the root via modelBuilder.Entity<Root>().UseTptMappingStrategy().","Audit OnModelCreating for stray UseXxxMappingStrategy calls on non-root entities."],"exampleFix":"// before\nmodelBuilder.Entity<Person>().UseTphMappingStrategy();\nmodelBuilder.Entity<Student>().UseTptMappingStrategy(); // error: derived\n// after (strategy set on root only)\nmodelBuilder.Entity<Person>().UseTptMappingStrategy();\n// Student inherits TPT from Person","handlingStrategy":"validation","validationCode":"using (var ctx = new MyContext()) { ctx.Model.ToDebugString(); }\n// Assert strategy is declared only on roots.\nforeach (var et in ctx.Model.GetEntityTypes())\n{\n    var s = (string?)et[Microsoft.EntityFrameworkCore.Metadata.RelationalAnnotationNames.MappingStrategy];\n    if (s != null && et.BaseType != null)\n        Debug.Fail($\"Derived type {et.Name} declares strategy '{s}'; set it on the root only.\");\n}","typeGuard":"static bool IsHierarchyRoot(Microsoft.EntityFrameworkCore.Metadata.IEntityType et) => et.BaseType == null;\n// Guard: only call UseXxxMappingStrategy() when IsHierarchyRoot(et) is true.","tryCatchPattern":"try { using var ctx = new MyContext(); _ = ctx.Model; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"mapping strategy\"))\n{ log.Error(\"Strategy set on a derived type; move it to the root: {Msg}\", ex.Message); throw; }","preventionTips":["Set UseXxxMappingStrategy once on the root entity only.","Search OnModelCreating for UseTph/Tpt/TpcMappingStrategy and confirm each call site targets a root type.","Cover strategy placement in a startup model-build test."],"tags":["ef-core","model-validation","inheritance","mapping-strategy","tpt","tpc"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}