From 05668cee7d4fc3beaff51ebee69200ec731c7fb9 Mon Sep 17 00:00:00 2001 From: Brice Lambson Date: Mon, 10 Aug 2020 14:34:14 -0700 Subject: [PATCH] Migrations: Order unmapped base class properties last Fixes #11314 --- .../Migrations/Internal/MigrationsModelDiffer.cs | 5 +++-- .../Migrations/Internal/MigrationsModelDifferTest.cs | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) 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)); }); }