-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
When migrating from EF6 to EF7, the EF7 generated model snapshot throws System.InvalidOperationException: Table name must be specified to configure a table-specific property mapping. when being applied. The generated snapshot also prevents the migration from being removed due to the same exception.
The base type is mapped to a custom table name and the expected behavior is that types inheriting from the base table should share the same table name without explicit configuration.
Only the .csproj and nuget libraries were updated to 7, no model or configuration changes were made.
EF Core 6 generated model:
modelBuilder.Entity("Domain.Aggregates.CustomerBalances.OutgoingCrossPlatformBalanceTransferLedgerEntry", b =>
{
b.HasBaseType("Domain.Aggregates.CustomerBalances.LedgerEntry");
b.Property<string>("TransferId")
.HasColumnType("text")
.HasColumnName("OutgoingCrossPlatformBalanceTransferLedgerEntry_TransferId"); //moved to b.ToTable() in EF7
b.HasIndex("TransferId")
.IsUnique();
b.HasDiscriminator().HasValue("OutgoingCrossPlatformBalanceTransferLedgerEntry");
});EF Core 7 generated model:
modelBuilder.Entity("Domain.Aggregates.CustomerBalances.OutgoingCrossPlatformBalanceTransferLedgerEntry", b =>
{
b.HasBaseType("Domain.Aggregates.CustomerBalances.LedgerEntry");
b.Property<string>("TransferId")
.HasColumnType("text");
b.HasIndex("TransferId")
.IsUnique();
//b.ToTable() generated code in EF7
//exception thrown: System.InvalidOperationException: Table name must be specified to configure a table-specific property mapping.
b.ToTable(t =>
{
t.Property("TransferId")
.HasColumnName("OutgoingCrossPlatformBalanceTransferLedgerEntry_TransferId");
});
b.HasDiscriminator().HasValue("OutgoingCrossPlatformBalanceTransferLedgerEntry");
});Config for base type:
public class LedgerEntryConfiguration : IEntityTypeConfiguration<LedgerEntry>
{
public void Configure(EntityTypeBuilder<LedgerEntry> builder)
{
builder.HasIndex(p => p.CreatedAt);
builder.ToTable("BalanceLedgerEntries");
}
}By adding builder.ToTable("BalanceLedgerEntries"); in the subtype configuration, the following is generated in the snapshot, which works:
b.ToTable("BalanceLedgerEntries", null, t =>
{
t.Property("TransferId")
.HasColumnName("OutgoingCrossPlatformBalanceTransferLedgerEntry_TransferId");
});