{"record":{"id":"6a14647d9e3cda7d","repo":"dotnet/efcore","slug":"the-type-entitytype-is-not-mapped-to-the-store","errorCode":null,"errorMessage":"The type '{entityType}' is not mapped to the store object '{table}'.","messagePattern":"The type '(.+?)' is not mapped to the store object '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs","lineNumber":1406,"sourceCode":"    /// </summary>\n    /// <param name=\"entityType\">The entity type.</param>\n    /// <param name=\"storeObject\">The identifier of the table-like store object.</param>\n    /// <returns>A value indicating whether the associated table is ignored by Migrations.</returns>\n    public static bool IsTableExcludedFromMigrations(\n        this IReadOnlyEntityType entityType,\n        in StoreObjectIdentifier storeObject)\n    {\n        if (entityType is RuntimeEntityType)\n        {\n            throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData);\n        }\n\n        var overrides = entityType.FindMappingFragment(storeObject);\n        return overrides != null\n            ? overrides.IsTableExcludedFromMigrations ?? entityType.IsTableExcludedFromMigrations()\n            : StoreObjectIdentifier.Create(entityType, storeObject.StoreObjectType) == storeObject\n                ? entityType.IsTableExcludedFromMigrations()\n                : throw new InvalidOperationException(\n                    RelationalStrings.TableNotMappedEntityType(entityType.DisplayName(), storeObject.DisplayName()));\n    }\n\n    /// <summary>\n    ///     Sets a value indicating whether the associated table is ignored by Migrations.\n    /// </summary>\n    /// <param name=\"entityType\">The entity type.</param>\n    /// <param name=\"excluded\">A value indicating whether the associated table is ignored by Migrations.</param>\n    public static void SetIsTableExcludedFromMigrations(this IMutableEntityType entityType, bool? excluded)\n        => entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.IsTableExcludedFromMigrations, excluded);\n\n    /// <summary>\n    ///     Sets a value indicating whether the associated table is ignored by Migrations.\n    /// </summary>\n    /// <param name=\"entityType\">The entity type.</param>\n    /// <param name=\"excluded\">A value indicating whether the associated table is ignored by Migrations.</param>\n    /// <param name=\"fromDataAnnotation\">Indicates whether the configuration was specified using a data annotation.</param>\n    /// <returns>The configured value.</returns>","sourceCodeStart":1388,"sourceCodeEnd":1424,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs#L1388-L1424","documentation":"The store-object overload of IsTableExcludedFromMigrations first checks for a mapping fragment, then falls back to verifying that StoreObjectIdentifier.Create(entityType, storeObjectType) equals the supplied storeObject. If neither holds, the entity is not mapped to that table, and the method throws TableNotMappedEntityType rather than returning a misleading value.","triggerScenarios":"Calling entityType.IsTableExcludedFromMigrations(storeObject) where the entity has no mapping fragment for that storeObject AND StoreObjectIdentifier.Create does not reproduce the same storeObject — i.e. the entity is genuinely not mapped to that table/view/sproc.","commonSituations":"Passing a StoreObjectIdentifier that belongs to a different entity; querying an override for a table the entity type does not map to; TPT/TPC hierarchies where the store object belongs to a sibling type.","solutions":["Verify the entity is actually mapped to the store object with StoreObjectIdentifier.Create(entityType, type) before calling.","Use the correct entity type for the store object in question.","If handling hierarchies, walk BaseType/derived types to find the mapped type.","Return early when FindMappingFragment(storeObject) is null and the create check fails."],"exampleFix":"// before\nvar so = StoreObjectIdentifier.Create(otherEntity, StoreObjectType.Table)!.Value;\nbool x = entity.IsTableExcludedFromMigrations(so);\n// after\nif (StoreObjectIdentifier.Create(entity, StoreObjectType.Table) is { } so)\n    bool x = entity.IsTableExcludedFromMigrations(so);","handlingStrategy":"validation","validationCode":"// Confirm the entity maps to the store object before calling.\nif (StoreObjectIdentifier.Create(entityType, storeObject.StoreObjectType) != storeObject)\n{\n    // entity is not mapped to this store object; do not call IsTableExcludedFromMigrations(storeObject).\n    return;\n}","typeGuard":"static bool IsMappedToStore(IEntityType et, in StoreObjectIdentifier so)\n    => StoreObjectIdentifier.Create(et, so.StoreObjectType) == so;","tryCatchPattern":"try { return entityType.IsTableExcludedFromMigrations(storeObject); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"is not mapped to the store object\"))\n{ return false; }","preventionTips":["Always verify StoreObjectIdentifier.Create reproduces the target before querying overrides.","In hierarchies, locate the type that actually owns the table.","Write tests asserting store objects align with entity mappings."],"tags":["store-object","table-mapping","entity-type","migrations"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}