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

Can't add migration renaming a column on TPC root #30321

Closed
roji opened this issue Feb 21, 2023 · 0 comments · Fixed by #30347
Closed

Can't add migration renaming a column on TPC root #30321

roji opened this issue Feb 21, 2023 · 0 comments · Fixed by #30347
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported Servicing-approved type-bug
Milestone

Comments

@roji
Copy link
Member

roji commented Feb 21, 2023

Console.WriteLine("Start");

public class MyContext : DbContext
{
    public DbSet<Campaign> Campaigns { get; set; }
    public DbSet<SearchCampaign> SearchCampaigns { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder.UseSqlServer("Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Campaign>(builder =>
        {
            builder.UseTpcMappingStrategy();

            // builder.Property(p => p.Status).HasColumnName("status_new");
        });
    }
}

public abstract class Campaign
{
    public int Id { get; set; }
    public int Status { get; set; }
}

public class SearchCampaign : Campaign
{
}

Create an initial migration for the above, then uncomment the line renaming the column and add a migration; this throws:

System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffContext.GetTable(IEntityType entityType) in /home/roji/projects/efcore/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs:line 2563
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.EntityTypePathEquals(IEntityType source, IEntityType target, DiffContext diffContext) in /home/roji/projects/efcore/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs:line 938
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.<>c__DisplayClass38_1.<Diff>b__7(IColumnMapping tm) in /home/roji/projects/efcore/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs:line 892
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.<>c__DisplayClass38_0.<Diff>b__6(IColumnMapping sm) in /home/roji/projects/efcore/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs:line 890
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.<>c.<Diff>b__38_2(IColumn s, IColumn t, DiffContext c) in /home/roji/projects/efcore/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs:line 888
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext() in /home/roji/projects/efcore/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs:line 2347
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(ITable source, ITable target, DiffContext diffContext)+MoveNext() in /home/roji/projects/efcore/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs:line 612
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext() in /home/roji/projects/efcore/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs:line 2362
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Sort(IEnumerable`1 operations, DiffContext diffContext) in /home/roji/projects/efcore/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs:line 150
   at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IRelationalModel source, IRelationalModel target) in /home/roji/projects/efcore/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs:line 115
   at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language) in /home/roji/projects/efcore/src/EFCore.Design/Migrations/Design/MigrationsScaffolder.cs:line 145
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace) in /home/roji/projects/efcore/src/EFCore.Design/Design/Internal/MigrationsOperations.cs:line 92
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace) in /home/roji/projects/efcore/src/EFCore.Design/Design/OperationExecutor.cs:line 180
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_1.<.ctor>b__0() in /home/roji/projects/efcore/src/EFCore.Design/Design/OperationExecutor.cs:line 168
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0() in /home/roji/projects/efcore/src/EFCore.Design/Design/OperationExecutor.cs:line 729
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) in /home/roji/projects/efcore/src/EFCore.Design/Design/OperationExecutor.cs:line 711

Confirmed the above throws for 7.0.3 and latest main, for TPC only. Originally reported as npgsql/efcore.pg#2652.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-migrations closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported Servicing-approved type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants