dotnet/efcore · error · InvalidOperationException
Table name must be specified to configure a table-specific p
Error message
Table name must be specified to configure a table-specific property mapping.
What it means
Thrown by TableBuilder.GetStoreObjectIdentifier() at TableBuilder.cs:164 when the StoreObject property is null. This occurs when table-specific property mapping configuration is attempted on a TableBuilder instance that was not created with a specific table name. The TableBuilder requires a StoreObjectIdentifier to know which table the column override applies to.
Source
Thrown at src/EFCore.Relational/Metadata/Builders/TableBuilder.cs:164
/// <summary>
/// Maps the property to a column on the current table and returns an object that can be used
/// to provide table-specific configuration if the property is mapped to more than one table.
/// </summary>
/// <typeparam name="TProperty">The type of the property to be configured.</typeparam>
/// <param name="propertyName">The name of the property to be configured.</param>
/// <returns>An object that can be used to configure the property.</returns>
public virtual ColumnBuilder<TProperty> Property<TProperty>(string propertyName)
=> new(GetStoreObjectIdentifier(), EntityTypeBuilder.Property<TProperty>(propertyName));
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
[EntityFrameworkInternal]
protected virtual StoreObjectIdentifier GetStoreObjectIdentifier()
=> StoreObject ?? throw new InvalidOperationException(RelationalStrings.MappingFragmentMissingName);
EntityTypeBuilder IInfrastructure<EntityTypeBuilder>.Instance
=> EntityTypeBuilder;
#region Hidden System.Object members
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <returns>A string that represents the current object.</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public override string? ToString()
=> base.ToString();
/// <summary>
/// Determines whether the specified object is equal to the current object.
/// </summary>
/// <param name="obj">The object to compare with the current object.</param>View on GitHub (pinned to dbf9771522)
Solutions
- Ensure ToTable("TableName", tb => { ... }) is used so the TableBuilder has a store object context.
- Use the entity-level Property configuration directly if per-table column overrides aren't needed.
- Verify you are chaining configuration from the ToTable callback parameter, not from a disconnected builder.
Example fix
// before: builder without table context
var tableBuilder = /* obtained without table name */;
tableBuilder.Property<string>("Name").HasColumnName("col_name"); // throws
// after: configure inside the ToTable callback
modelBuilder.Entity<MyEntity>()
.ToTable("MyTable", tb =>
{
tb.Property<string>("Name").HasColumnName("col_name");
}); Defensive patterns
Strategy: validation
Validate before calling
// Always configure table-specific overrides inside the ToTable callback where StoreObject is set.
modelBuilder.Entity<MyEntity>().ToTable("MyTable", tb =>
{
tb.Property<string>("Name").HasColumnName("col_name");
}); Prevention
- Use the ToTable(name, Action<TableBuilder>) overload so the builder always has a store object.
- Avoid constructing TableBuilder instances directly.
When it happens
Trigger: Calling .Property<T>("ColName").HasColumnName(...) on a TableBuilder whose StoreObject is null — happens when the builder was obtained without a table context, e.g., through an internal API path that didn't initialize the store object.
Common situations: Attempting table-specific column overrides before the entity is mapped to a table. Misusing the builder API or constructing a TableBuilder directly without a StoreObject. API misuse during complex mapping scenarios with multiple tables.
Related errors
- Table name must be specified to configure a table-specific p
- Invalid number of index sort order values: {numValues} value
- IsDescending and AllDescending cannot both be specified on t
- The number argument cannot be a negative number.
- The value '{value}' provided for argument '{argumentName}' m
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/5aac247493b8b0a7.
Report an issue: GitHub.