{"record":{"id":"028c0fdc5338b36c","repo":"dotnet/efcore","slug":"the-mapping-strategy-mappingstrategy-specified-028c0f","errorCode":null,"errorMessage":"The mapping strategy '{mappingStrategy}' specified on '{entityType}' is not supported.","messagePattern":"The mapping strategy '(.+?)' specified on '(.+?)' is not supported\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":2201,"sourceCode":"            }\n        }\n    }\n\n    /// <summary>\n    ///     Validates that the given mapping strategy is supported\n    /// </summary>\n    /// <param name=\"entityType\">The entity type.</param>\n    /// <param name=\"mappingStrategy\">The mapping strategy.</param>\n    protected virtual void ValidateMappingStrategy(IEntityType entityType, string? mappingStrategy)\n    {\n        switch (mappingStrategy)\n        {\n            case RelationalAnnotationNames.TphMappingStrategy:\n            case RelationalAnnotationNames.TpcMappingStrategy:\n            case RelationalAnnotationNames.TptMappingStrategy:\n                break;\n            default:\n                throw new InvalidOperationException(\n                    RelationalStrings.InvalidMappingStrategy(\n                        mappingStrategy, entityType.DisplayName()));\n        }\n    }\n\n    private static void ValidateNonTphMapping(IEntityType rootEntityType, StoreObjectType storeObjectType)\n    {\n        var isTpc = rootEntityType.GetMappingStrategy() == RelationalAnnotationNames.TpcMappingStrategy;\n        var derivedTypes = new Dictionary<StoreObjectIdentifier, IEntityType>();\n        foreach (var entityType in rootEntityType.GetDerivedTypesInclusive())\n        {\n            var storeObject = StoreObjectIdentifier.Create(entityType, storeObjectType);\n            if (storeObject == null)\n            {\n                var unmappedOwnedType = entityType.GetReferencingForeignKeys()\n                    .Where(fk => fk.IsOwnership)\n                    .Select(fk => fk.DeclaringEntityType)\n                    .FirstOrDefault(owned => StoreObjectIdentifier.Create(owned, storeObjectType) == null","sourceCodeStart":2183,"sourceCodeEnd":2219,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2183-L2219","documentation":"Thrown by ValidateMappingStrategy when the mapping strategy string set on an entity type is not one of the recognized values (TPH, TPC, TPT). The switch falls through to the default case, so any unknown/misspelled strategy annotation is rejected at validation time.","triggerScenarios":"Calling SetMappingStrategy with a typo or unsupported value (e.g. \"TPTT\", \"TablePerHierarchy\", \"tpt\" with wrong casing/format), or writing the RelationalAnnotationNames.MappingStrategy annotation directly with an invalid string.","commonSituations":"Hand-writing the annotation string instead of using UseTptMappingStrategy()/UseTpcMappingStrategy()/UseTphMappingStrategy(); custom conventions that set the annotation; casing/whitespace mistakes; stale code referencing a renamed strategy constant.","solutions":["Use the fluent API: UseTphMappingStrategy(), UseTptMappingStrategy(), or UseTpcMappingStrategy().","If setting the annotation directly, use RelationalAnnotationNames.TphMappingStrategy / TpcMappingStrategy / TptMappingStrategy constants, never literals.","Check for trailing spaces or wrong casing in any custom convention that writes the strategy."],"exampleFix":"// before\nmodelBuilder.Entity<Order>()\n    .Metadata.SetAnnotation(\"Relational:MappingStrategy\", \"TablePerType\"); // unknown -> throws 424\n\n// after\nmodelBuilder.Entity<Order>().UseTptMappingStrategy();","handlingStrategy":"validation","validationCode":"var allowed = new HashSet<string?>\n{\n    null,\n    RelationalAnnotationNames.TphMappingStrategy,\n    RelationalAnnotationNames.TptMappingStrategy,\n    RelationalAnnotationNames.TpcMappingStrategy,\n};\nforeach (var entityType in modelBuilder.Model.GetEntityTypes())\n{\n    var strategy = (string?)entityType[RelationalAnnotationNames.MappingStrategy];\n    if (!allowed.Contains(strategy))\n        throw new InvalidOperationException($\"{entityType.DisplayName()} has unknown mapping strategy '{strategy}'.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use UseTphMappingStrategy()/UseTptMappingStrategy()/UseTpcMappingStrategy() instead of writing the annotation directly.","If you must write the annotation, reference the RelationalAnnotationNames constants, never literals.","Add a test that asserts every entity's mapping strategy is one of the three known values."],"tags":["ef-core","model-validation","mapping","inheritance","tph","tpt","tpc","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}