{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2072-L2108","documentation":"A derived entity type (one with a non-null BaseType) was explicitly configured with a mapping strategy (TPH/TPT/TPC). Mapping strategy is a hierarchy-wide setting that must be declared once on the root entity type; configuring it on a derived type is ambiguous and EF rejects it. Even if the strategy matches the base, only the root may carry the annotation.","triggerScenarios":"ValidateInheritanceMapping detects entityType.BaseType != null and a non-null mappingStrategy annotation that is either absent on the base or differs from the base's strategy; throws RelationalStrings.DerivedStrategy. Triggered by calling UseTphMappingStrategy()/UseTptMappingStrategy()/UseTpcMappingStrategy() on a derived entity.","commonSituations":"Copy-pasting UseTpcMappingStrategy() onto every entity in a hierarchy; refactoring a hierarchy and leaving strategy calls on the old root that became derived; scaffolding customizations that added strategy on a child.","solutions":["Remove the UseTphMappingStrategy()/UseTptMappingStrategy()/UseTpcMappingStrategy() call from the derived entity type.","Apply the strategy only on the root entity type of the hierarchy.","If the root was supposed to be different, restructure the hierarchy so the configured type is actually the root."],"exampleFix":"// before\nmodelBuilder.Entity<Animal>().UseTpcMappingStrategy();\nmodelBuilder.Entity<Dog>().UseTpcMappingStrategy(); // Dog is derived -> error\n\n// after - strategy declared only on the root\nmodelBuilder.Entity<Animal>().UseTpcMappingStrategy();","handlingStrategy":"validation","validationCode":"// Strategy may only be set on root entity types.\nforeach (var et in db.Model.GetEntityTypes())\n{\n    var strategy = et[RelationalAnnotationNames.MappingStrategy] as string;\n    if (strategy != null && et.BaseType != null)\n        Console.WriteLine($\"Derived type {et.Name} incorrectly declares strategy {strategy}\");\n}","typeGuard":"static bool IsHierarchyRoot(IEntityType et) => et.BaseType == null;","tryCatchPattern":"try { _ = db.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains(\"configured with the\") && ex.Message.Contains(\"mapping strategy\")) { // remove the strategy call from the derived entity }","preventionTips":["Call UseTphMappingStrategy/UseTptMappingStrategy/UseTpcMappingStrategy only on the root entity.","During code review, flag any mapping-strategy call inside a configuration for a derived type.","Add a startup test that builds the model for the hierarchy."],"tags":["model-validation","inheritance","mapping-strategy","tph","tpt","tpc","relational"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}