diff --git a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs index ae9a0cbdc10..438d7cbea95 100644 --- a/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs +++ b/src/EFCore.Relational/Migrations/Internal/MigrationsModelDiffer.cs @@ -827,9 +827,10 @@ private static IEnumerable GetSortedProperties(IEntityType entityType .Select(pi => primaryKeyPropertyGroups.ContainsKey(pi) ? primaryKeyPropertyGroups[pi] : null) .Where(e => e != null) .Concat(leastPriorityPrimaryKeyProperties) - .Concat(sortedPropertyInfos.Where(pi => !primaryKeyPropertyGroups.ContainsKey(pi)).SelectMany(p => groups[p])) + .Concat(sortedPropertyInfos.Where(pi => !primaryKeyPropertyGroups.ContainsKey(pi) && entityType.ClrType.IsAssignableFrom(pi.DeclaringType)).SelectMany(p => groups[p])) .Concat(leastPriorityProperties) - .Concat(entityType.GetDirectlyDerivedTypes().SelectMany(et => GetSortedProperties(et, table))); + .Concat(entityType.GetDirectlyDerivedTypes().SelectMany(et => GetSortedProperties(et, table))) + .Concat(sortedPropertyInfos.Where(pi => !primaryKeyPropertyGroups.ContainsKey(pi) && !entityType.ClrType.IsAssignableFrom(pi.DeclaringType)).SelectMany(p => groups[p])); } private sealed class PropertyInfoEqualityComparer : IEqualityComparer diff --git a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs index 8897ebcef10..602f313d026 100644 --- a/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs +++ b/test/EFCore.Relational.Tests/Migrations/Internal/MigrationsModelDifferTest.cs @@ -9619,10 +9619,10 @@ var dependentTableCreation c => Assert.Equal("Id2", c.Name), c => Assert.Equal("Id1", c.Name), c => Assert.Equal("ShadowPk", c.Name), - c => Assert.Equal("RealFkNavigationId", c.Name), - c => Assert.Equal("ShadowFkNavigationId", c.Name), c => Assert.Equal("Value", c.Name), - c => Assert.Equal("AnotherShadowProperty", c.Name)); + c => Assert.Equal("AnotherShadowProperty", c.Name), + c => Assert.Equal("RealFkNavigationId", c.Name), + c => Assert.Equal("ShadowFkNavigationId", c.Name)); }); }