dotnet/efcore · error · InvalidOperationException
The type '{entityType}' is not mapped to the store object '{
Error message
The type '{entityType}' is not mapped to the store object '{table}'. What it means
Thrown by IsTableExcludedFromMigrations(storeObject) when the entity type is not mapped to the requested store object at all (RelationalEntityTypeExtensions.cs:1406, RelationalStrings.TableNotMappedEntityType). The per-table overload is only valid for tables the entity is actually mapped to.
Source
Thrown at src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs:1406
/// </summary>
/// <param name="entityType">The entity type.</param>
/// <param name="storeObject">The identifier of the table-like store object.</param>
/// <returns>A value indicating whether the associated table is ignored by Migrations.</returns>
public static bool IsTableExcludedFromMigrations(
this IReadOnlyEntityType entityType,
in StoreObjectIdentifier storeObject)
{
if (entityType is RuntimeEntityType)
{
throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData);
}
var overrides = entityType.FindMappingFragment(storeObject);
return overrides != null
? overrides.IsTableExcludedFromMigrations ?? entityType.IsTableExcludedFromMigrations()
: StoreObjectIdentifier.Create(entityType, storeObject.StoreObjectType) == storeObject
? entityType.IsTableExcludedFromMigrations()
: throw new InvalidOperationException(
RelationalStrings.TableNotMappedEntityType(entityType.DisplayName(), storeObject.DisplayName()));
}
/// <summary>
/// Sets a value indicating whether the associated table is ignored by Migrations.
/// </summary>
/// <param name="entityType">The entity type.</param>
/// <param name="excluded">A value indicating whether the associated table is ignored by Migrations.</param>
public static void SetIsTableExcludedFromMigrations(this IMutableEntityType entityType, bool? excluded)
=> entityType.SetOrRemoveAnnotation(RelationalAnnotationNames.IsTableExcludedFromMigrations, excluded);
/// <summary>
/// Sets a value indicating whether the associated table is ignored by Migrations.
/// </summary>
/// <param name="entityType">The entity type.</param>
/// <param name="excluded">A value indicating whether the associated table is ignored by Migrations.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>View on GitHub (pinned to dbf9771522)
Solutions
- Verify the mapping before querying: if (StoreObjectIdentifier.Create(entityType, StoreObjectType.Table) == storeObject) ... else skip.
- Use the parameterless IsTableExcludedFromMigrations() for the entity's primary mapped table.
- Correct the table/schema name or call against the entity type that actually owns that table.
Example fix
// before
var so = StoreObjectIdentifier.Table("AuditLog", "dbo");
var excl = orderEntity.IsTableExcludedFromMigrations(so); // Order isn't mapped to AuditLog
// after
if (StoreObjectIdentifier.Create(orderEntity, StoreObjectType.Table) is { } mappedSo)
{
var excl = orderEntity.IsTableExcludedFromMigrations(mappedSo);
} Defensive patterns
Strategy: validation
Validate before calling
var so = StoreObjectIdentifier.Table("Orders", "dbo");
if (StoreObjectIdentifier.Create(entityType, StoreObjectType.Table) == so)
{
var excl = entityType.IsTableExcludedFromMigrations(so);
} Prevention
- Only call IsTableExcludedFromMigrations(storeObject) for tables the entity is mapped to.
- When iterating all tables, filter to those returned by StoreObjectIdentifier.Create per entity.
- Double-check schema/table names for typos.
When it happens
Trigger: Passing a StoreObjectIdentifier for a table/view the entity is not mapped to — e.g. a TPT sibling table, a derived type's table queried against its base type, or a typo in table/schema name.
Common situations: Iterating all tables in the model and calling IsTableExcludedFromMigrations for every entity; mixing up the declaring vs. principal table in table splitting; passing the wrong schema.
Related errors
- The property '{property}' on entity type '{entityType}' is n
- The requested configuration is not stored in the read-optimi
- The requested configuration is not stored in the read-optimi
- 'Except' cannot be called on the builder returned by 'HasAut
- The type '{clrType}' is being used as a vector, but the vect
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/6a14647d9e3cda7d.
Report an issue: GitHub.