Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception while applying migration with model containing descendant types with same property names #29579

Closed
stanislav-a-frolov opened this issue Nov 16, 2022 · 1 comment

Comments

@stanislav-a-frolov
Copy link

Hi, everyone.

When I try make migrations in efcore 7.0.0 for the following types:

public abstract class BaseModel
{
    public int Id { get; set; }
    public string Property { get; set; }
    public string Type { get; set; }

}

public class Model1: BaseModel
{
    public string Property2 { get; set; }

}
public class Model2 : BaseModel
{
    public string Property3 { get; set; }

}

I get exception while trying to apply migration:

   at Microsoft.EntityFrameworkCore.Metadata.Builders.TableBuilder.GetStoreObjectIdentifier()
   at Microsoft.EntityFrameworkCore.Metadata.Builders.TableBuilder.Property(String propertyName)
   at TestEf7Migrations.Migrations.Initial.<>c.<BuildTargetModel>b__2_3(TableBuilder t) in D:\sfrolov\Projects\TestEf7Migrations\TestEf7Migrations\Migrations\20221116063446_Initial.Designer.cs:line 73
   at Microsoft.EntityFrameworkCore.RelationalEntityTypeBuilderExtensions.ToTable(EntityTypeBuilder entityTypeBuilder, Action`1 buildAction)
   at TestEf7Migrations.Migrations.Initial.<>c.<BuildTargetModel>b__2_2(EntityTypeBuilder b) in D:\sfrolov\Projects\TestEf7Migrations\TestEf7Migrations\Migrations\20221116063446_Initial.Designer.cs:line 71
   at Microsoft.EntityFrameworkCore.ModelBuilder.Entity(String name, Action`1 buildAction)
   at TestEf7Migrations.Migrations.Initial.BuildTargetModel(ModelBuilder modelBuilder) in D:\sfrolov\Projects\TestEf7Migrations\TestEf7Migrations\Migrations\20221116063446_Initial.Designer.cs:line 63
   at Microsoft.EntityFrameworkCore.Migrations.Migration.<get_TargetModel>g__Create|5_0()
   at Microsoft.EntityFrameworkCore.Migrations.Migration.get_TargetModel()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.GenerateUpSql(Migration migration, MigrationsSqlGenerationOptions options)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.<>c__DisplayClass16_2.<GetMigrationCommandLists>b__2()
   at Mic
rosoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Table name must be specified to configure a table-specific property mapping.

The problem is in .Designer file of migration in the following lines:

                    b.ToTable(t =>
                        {
                            t.Property("Property2")
                                .HasColumnName("Model2_Property2");
                        });

Steps to reproduce with included project.

  1. Open included solution TestEf7Migrations.zip, add a connection string to AppDbContextDesignTimeFactory.cs
  2. Run in powershell:
    dotnet ef migrations add Initial --project TestEf7Migrations
    then
    dotnet ef database update Initial --project TestEf7Migrations

Packages in solution:

@ajcvickers
Copy link
Contributor

Duplicate of #29534.

@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants