diff --git a/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs b/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs index fe28ee86dc2..b6747539b35 100644 --- a/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs @@ -1379,13 +1379,16 @@ public static bool IsTableExcludedFromMigrations(this IReadOnlyEntityType entity return excluded.Value; } - if (entityType.BaseType != null) + if (entityType.BaseType != null + && entityType.GetMappingStrategy() == RelationalAnnotationNames.TphMappingStrategy) { return entityType.GetRootType().IsTableExcludedFromMigrations(); } var ownership = entityType.FindOwnership(); - if (ownership is { IsUnique: true }) + if (ownership is { IsUnique: true } + && ownership.DeclaringEntityType.GetTableName() == entityType.GetTableName() + && ownership.DeclaringEntityType.GetSchema() == entityType.GetSchema()) { return ownership.PrincipalEntityType.IsTableExcludedFromMigrations(); } diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs index 47251be8f88..a14998c9fd4 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs @@ -558,7 +558,7 @@ protected virtual IEnumerable Diff( DiffContext diffContext) { if (source.IsExcludedFromMigrations - && target.IsExcludedFromMigrations) + || target.IsExcludedFromMigrations) { // Populate column mapping foreach (var _ in Diff(source.Columns, target.Columns, diffContext)) diff --git a/test/EFCore.Cosmos.FunctionalTests/ConfigPatternsCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/ConfigPatternsCosmosTest.cs index 95601921d87..daaa5d8b6fb 100644 --- a/test/EFCore.Cosmos.FunctionalTests/ConfigPatternsCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/ConfigPatternsCosmosTest.cs @@ -88,7 +88,7 @@ public async Task Should_throw_if_specified_region_is_wrong() exception.Message); } - [ConditionalFact(Skip = "Issue #runtime/issues/89118")] + [ConditionalFact] public async Task Should_not_throw_if_specified_connection_mode_is_right() { var connectionMode = ConnectionMode.Direct; diff --git a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs index 4007248e37b..b0f732c5b56 100644 --- a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs +++ b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs @@ -8284,6 +8284,62 @@ public void Change_TPT_to_TPC_with_FKs_and_seed_data() Assert.Equal(ReferentialAction.Cascade, operation.OnDelete); })); + [ConditionalFact] + public void Change_TPT_to_TPC_with_excluded_base() + => Execute( + common => + { + common.Entity( + "Order", + x => + { + x.ToTable("Order", t => t.ExcludeFromMigrations()); + x.Property("Id"); + x.Property("Address"); + }); + common.Entity( + "DetailedOrder", + x => + { + x.ToTable("DetailedOrder"); + x.HasBaseType("Order"); + x.Property("Description").HasColumnName("Description"); + }); + }, + _ => { }, + target => + { + target.Entity("Order").UseTpcMappingStrategy(); + }, + upOperations => + { + Assert.Equal(2, upOperations.Count); + + var dropForeignKeyOperation = Assert.IsType(upOperations[0]); + Assert.Null(dropForeignKeyOperation.Schema); + Assert.Equal("DetailedOrder", dropForeignKeyOperation.Table); + Assert.Equal("FK_DetailedOrder_Order_Id", dropForeignKeyOperation.Name); + + var addColumnOperation = Assert.IsType(upOperations[1]); + Assert.Null(addColumnOperation.Schema); + Assert.Equal("DetailedOrder", addColumnOperation.Table); + Assert.Equal("Address", addColumnOperation.Name); + }, + downOperations => + { + Assert.Equal(2, downOperations.Count); + + var dropColumnOperation = Assert.IsType(downOperations[0]); + Assert.Null(dropColumnOperation.Schema); + Assert.Equal("DetailedOrder", dropColumnOperation.Table); + Assert.Equal("Address", dropColumnOperation.Name); + + var addForeignKeyOperation = Assert.IsType(downOperations[1]); + Assert.Null(addForeignKeyOperation.Schema); + Assert.Equal("DetailedOrder", addForeignKeyOperation.Table); + Assert.Equal("FK_DetailedOrder_Order_Id", addForeignKeyOperation.Name); + }); + [ConditionalFact] public void Add_foreign_key_on_base_type() => Execute(