diff --git a/src/EFCore.Relational/Metadata/Internal/RelationalModel.cs b/src/EFCore.Relational/Metadata/Internal/RelationalModel.cs index ec56f0d010b..c3deafae37d 100644 --- a/src/EFCore.Relational/Metadata/Internal/RelationalModel.cs +++ b/src/EFCore.Relational/Metadata/Internal/RelationalModel.cs @@ -820,7 +820,7 @@ private static void PopulateConstraints(Table table) if (columns.SequenceEqual(principalColumns)) { // Principal and dependent properties are mapped to the same columns so the constraint is redundant - continue; + break; } constraint = new ForeignKeyConstraint(name, table, principalTable, columns, principalColumns, diff --git a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs index 4bb76d32403..545a6888617 100644 --- a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs +++ b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs @@ -1760,6 +1760,51 @@ public void Rename_property_and_column_when_snapshot() skipSourceConventions: true); } + [ConditionalFact] + public void Add_table_sharing_to_TPT() + { + Execute( + common => { + common.Entity( + "Order", + x => + { + x.ToTable("Order"); + x.Property("Id"); + }); + common.Entity( + "DetailedOrder", + x => + { + x.ToTable("DetailedOrder"); + x.HasBaseType("Order"); + x.Property("Description").HasColumnName("Description"); + }); + }, + _ => { }, + target => { + target.Entity( + "OrderDetails", + x => + { + x.ToTable("DetailedOrder"); + x.Property("Id"); + x.Property("Description").HasColumnName("Description"); + x.Property("OrderDate"); + x.HasOne("DetailedOrder", null).WithOne().HasForeignKey("OrderDetails", "Id"); + }); + }, + operations => + { + Assert.Equal(1, operations.Count); + + var operation = Assert.IsType(operations[0]); + Assert.Null(operation.Schema); + Assert.Equal("DetailedOrder", operation.Table); + Assert.Equal("OrderDate", operation.Name); + }); + } + [ConditionalFact] public void Rename_column_in_TPT_with_table_sharing_and_seed_data() {