Skip to content

Commit

Permalink
Don't create an FK constraint if a derived type in TPT uses table sha…
Browse files Browse the repository at this point in the history
…ring
  • Loading branch information
AndriySvyryd authored Aug 18, 2020
1 parent 10d9bb9 commit 245f20b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Metadata/Internal/RelationalModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>("Id");
});
common.Entity(
"DetailedOrder",
x =>
{
x.ToTable("DetailedOrder");
x.HasBaseType("Order");
x.Property<string>("Description").HasColumnName("Description");
});
},
_ => { },
target => {
target.Entity(
"OrderDetails",
x =>
{
x.ToTable("DetailedOrder");
x.Property<int>("Id");
x.Property<string>("Description").HasColumnName("Description");
x.Property<DateTime>("OrderDate");
x.HasOne("DetailedOrder", null).WithOne().HasForeignKey("OrderDetails", "Id");
});
},
operations =>
{
Assert.Equal(1, operations.Count);
var operation = Assert.IsType<AddColumnOperation>(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()
{
Expand Down

0 comments on commit 245f20b

Please sign in to comment.