{"record":{"id":"3308cfbd66ddfb4d","repo":"dotnet/efcore","slug":"the-entity-type-entitytype-cannot-be-instantia-3308cf","errorCode":null,"errorMessage":"The entity type '{entityType}' cannot be instantiated because its corresponding CLR type is abstract, but the entity type was mapped to '{storeObject}' using the 'TPC' mapping strategy. Only instantiable types should be mapped. See https://go.microsoft.com/fwlink/?linkid=2130430 for more information.","messagePattern":"The entity type '(.+?)' cannot be instantiated because its corresponding CLR type is abstract, but the entity type was mapped to '(.+?)' using the 'TPC' mapping strategy\\. Only instantiable types should be mapped\\. 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":2080,"sourceCode":"        IEntityType entityType,\n        IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)\n    {\n        var mappingStrategy = (string?)entityType[RelationalAnnotationNames.MappingStrategy];\n        if (mappingStrategy != null)\n        {\n            ValidateMappingStrategy(entityType, mappingStrategy);\n            var storeObjectName = entityType.GetSchemaQualifiedTableName()\n                ?? entityType.GetSchemaQualifiedViewName()\n                ?? entityType.GetFunctionName()\n                ?? 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)","sourceCodeStart":2062,"sourceCodeEnd":2098,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2062-L2098","documentation":"An entity type whose CLR type is abstract (cannot be instantiated) was mapped to a concrete store object (table/view/function/stored procedure) using the TPC (Table-per-Concrete-type) mapping strategy. TPC gives each type its own table, so abstract types - which can never be queried or inserted as instances - must not be mapped to a store object. Thrown from ValidateInheritanceMapping when mappingStrategy == Tpc and the CLR type is not instantiable.","triggerScenarios":"Calling modelBuilder.Entity<AbstractBase>().UseTpcMappingStrategy() where AbstractBase is an abstract C# class that also resolves to a table (e.g. via ToTable or default convention); configuring a TPC hierarchy root whose base class is abstract and ends up with a table mapping.","commonSituations":"Migrating from TPH/TPC and forgetting to mark the abstract base as unmapped; convention-based ToTable on an abstract root in a TPC hierarchy; refactoring a base class to abstract without removing its table mapping.","solutions":["Remove the table/view/function mapping from the abstract base (do not call ToTable on it; in TPC the base should not be a store object).","If the base must participate, make its CLR class concrete (sealed or non-abstract), though usually the right fix is to leave it abstract and unmapped.","Confirm UseTpcMappingStrategy is only declared on the concrete root or each concrete derived type as supported by the provider."],"exampleFix":"// before\npublic abstract class Animal { public int Id { get; set; } }\nmodelBuilder.Entity<Animal>().ToTable(\"Animals\").UseTpcMappingStrategy();\n// after (abstract base is not mapped to a store object in TPC)\npublic abstract class Animal { public int Id { get; set; } }\nmodelBuilder.Entity<Animal>().UseTpcMappingStrategy();\n// 'Animals' table is removed; only Cat/Dog tables exist","handlingStrategy":"validation","validationCode":"using (var ctx = new MyContext()) { ctx.Model.ToDebugString(); }\n// Assert that no abstract entity in a TPC hierarchy is mapped to a store object.\nforeach (var et in ctx.Model.GetEntityTypes())\n{\n    var strategy = et.GetMappingStrategy();\n    if (strategy == \"TPC\" && et.ClrType.IsAbstract)\n    {\n        var table = et.GetSchemaQualifiedTableName() ?? et.GetSchemaQualifiedViewName();\n        Debug.Assert(table == null, $\"Abstract type {et.Name} is mapped to '{table}' under TPC.\");\n    }\n}","typeGuard":"static bool IsInstantiable(Type t) => !t.IsAbstract && !t.IsGenericTypeDefinition && !t.IsInterface;\n// Guard: do not call .Entity<T>().ToTable(...) when IsInstantiable(typeof(T)) is false in TPC.","tryCatchPattern":"try { using var ctx = new MyContext(); _ = ctx.Model; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"abstract\") && ex.Message.Contains(\"TPC\"))\n{ log.Error(\"Abstract type mapped in TPC; remove its ToTable mapping: {Msg}\", ex.Message); throw; }","preventionTips":["Never call ToTable/ToView on an abstract base in a TPC hierarchy.","Add a startup model-build test that asserts abstract TPC types have no store object.","When refactoring a base class to abstract, sweep OnModelCreating for stray mappings."],"tags":["ef-core","model-validation","tpc","inheritance","abstract"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}