From aa8d469b20308545e19d5e65a62258f6aca54d46 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Tue, 24 Mar 2020 19:10:45 +0000 Subject: [PATCH 1/5] Update dependencies from https://github.com/dotnet/efcore build 20200324.2 - Microsoft.EntityFrameworkCore.Tools - 5.0.0-preview.3.20174.2 - Microsoft.EntityFrameworkCore.SqlServer - 5.0.0-preview.3.20174.2 - dotnet-ef - 5.0.0-preview.3.20174.2 - Microsoft.EntityFrameworkCore - 5.0.0-preview.3.20174.2 - Microsoft.EntityFrameworkCore.InMemory - 5.0.0-preview.3.20174.2 - Microsoft.EntityFrameworkCore.Relational - 5.0.0-preview.3.20174.2 - Microsoft.EntityFrameworkCore.Sqlite - 5.0.0-preview.3.20174.2 --- eng/Version.Details.xml | 28 ++++++++++++++-------------- eng/Versions.props | 14 +++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index f545658d93d0..6613f3863033 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -29,33 +29,33 @@ https://github.com/dotnet/aspnetcore-tooling dcbab464643d971765e77562d2d0854c6ae112f7 - + https://github.com/dotnet/efcore - ac4633559b117b92156d75f07b7ef81dc920b4fd + c0e2ec2163bfd935dc6a6b8926da77b566d9951b - + https://github.com/dotnet/efcore - ac4633559b117b92156d75f07b7ef81dc920b4fd + c0e2ec2163bfd935dc6a6b8926da77b566d9951b - + https://github.com/dotnet/efcore - ac4633559b117b92156d75f07b7ef81dc920b4fd + c0e2ec2163bfd935dc6a6b8926da77b566d9951b - + https://github.com/dotnet/efcore - ac4633559b117b92156d75f07b7ef81dc920b4fd + c0e2ec2163bfd935dc6a6b8926da77b566d9951b - + https://github.com/dotnet/efcore - ac4633559b117b92156d75f07b7ef81dc920b4fd + c0e2ec2163bfd935dc6a6b8926da77b566d9951b - + https://github.com/dotnet/efcore - ac4633559b117b92156d75f07b7ef81dc920b4fd + c0e2ec2163bfd935dc6a6b8926da77b566d9951b - + https://github.com/dotnet/efcore - ac4633559b117b92156d75f07b7ef81dc920b4fd + c0e2ec2163bfd935dc6a6b8926da77b566d9951b https://github.com/dotnet/extensions diff --git a/eng/Versions.props b/eng/Versions.props index 4d507eba31f7..787c2ed9595f 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -139,13 +139,13 @@ 5.0.0-preview.3.20170.1 5.0.0-preview.3.20170.1 - 5.0.0-preview.3.20170.2 - 5.0.0-preview.3.20170.2 - 5.0.0-preview.3.20170.2 - 5.0.0-preview.3.20170.2 - 5.0.0-preview.3.20170.2 - 5.0.0-preview.3.20170.2 - 5.0.0-preview.3.20170.2 + 5.0.0-preview.3.20174.2 + 5.0.0-preview.3.20174.2 + 5.0.0-preview.3.20174.2 + 5.0.0-preview.3.20174.2 + 5.0.0-preview.3.20174.2 + 5.0.0-preview.3.20174.2 + 5.0.0-preview.3.20174.2 5.0.0-preview.3.20170.3 5.0.0-preview.3.20170.3 From 80ed77cf177977fa719a592ab7e684cc52ba98ef Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Tue, 24 Mar 2020 20:10:49 +0000 Subject: [PATCH 2/5] Update dependencies from https://github.com/dotnet/efcore build 20200324.3 - Microsoft.EntityFrameworkCore.Tools - 5.0.0-preview.3.20174.3 - Microsoft.EntityFrameworkCore.SqlServer - 5.0.0-preview.3.20174.3 - dotnet-ef - 5.0.0-preview.3.20174.3 - Microsoft.EntityFrameworkCore - 5.0.0-preview.3.20174.3 - Microsoft.EntityFrameworkCore.InMemory - 5.0.0-preview.3.20174.3 - Microsoft.EntityFrameworkCore.Relational - 5.0.0-preview.3.20174.3 - Microsoft.EntityFrameworkCore.Sqlite - 5.0.0-preview.3.20174.3 --- eng/Version.Details.xml | 28 ++++++++++++++-------------- eng/Versions.props | 14 +++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 6613f3863033..34d0eb3d19a2 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -29,33 +29,33 @@ https://github.com/dotnet/aspnetcore-tooling dcbab464643d971765e77562d2d0854c6ae112f7 - + https://github.com/dotnet/efcore - c0e2ec2163bfd935dc6a6b8926da77b566d9951b + 9b1f0a0f11edf8a3ec4319493da46082f194dc33 - + https://github.com/dotnet/efcore - c0e2ec2163bfd935dc6a6b8926da77b566d9951b + 9b1f0a0f11edf8a3ec4319493da46082f194dc33 - + https://github.com/dotnet/efcore - c0e2ec2163bfd935dc6a6b8926da77b566d9951b + 9b1f0a0f11edf8a3ec4319493da46082f194dc33 - + https://github.com/dotnet/efcore - c0e2ec2163bfd935dc6a6b8926da77b566d9951b + 9b1f0a0f11edf8a3ec4319493da46082f194dc33 - + https://github.com/dotnet/efcore - c0e2ec2163bfd935dc6a6b8926da77b566d9951b + 9b1f0a0f11edf8a3ec4319493da46082f194dc33 - + https://github.com/dotnet/efcore - c0e2ec2163bfd935dc6a6b8926da77b566d9951b + 9b1f0a0f11edf8a3ec4319493da46082f194dc33 - + https://github.com/dotnet/efcore - c0e2ec2163bfd935dc6a6b8926da77b566d9951b + 9b1f0a0f11edf8a3ec4319493da46082f194dc33 https://github.com/dotnet/extensions diff --git a/eng/Versions.props b/eng/Versions.props index 787c2ed9595f..734706e6b17c 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -139,13 +139,13 @@ 5.0.0-preview.3.20170.1 5.0.0-preview.3.20170.1 - 5.0.0-preview.3.20174.2 - 5.0.0-preview.3.20174.2 - 5.0.0-preview.3.20174.2 - 5.0.0-preview.3.20174.2 - 5.0.0-preview.3.20174.2 - 5.0.0-preview.3.20174.2 - 5.0.0-preview.3.20174.2 + 5.0.0-preview.3.20174.3 + 5.0.0-preview.3.20174.3 + 5.0.0-preview.3.20174.3 + 5.0.0-preview.3.20174.3 + 5.0.0-preview.3.20174.3 + 5.0.0-preview.3.20174.3 + 5.0.0-preview.3.20174.3 5.0.0-preview.3.20170.3 5.0.0-preview.3.20170.3 From 9dbb121b13c412c751c1bd0dec2475875ca40774 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Tue, 24 Mar 2020 21:25:48 +0000 Subject: [PATCH 3/5] Update dependencies from https://github.com/dotnet/efcore build 20200324.4 - Microsoft.EntityFrameworkCore.Tools - 5.0.0-preview.3.20174.4 - Microsoft.EntityFrameworkCore.SqlServer - 5.0.0-preview.3.20174.4 - dotnet-ef - 5.0.0-preview.3.20174.4 - Microsoft.EntityFrameworkCore - 5.0.0-preview.3.20174.4 - Microsoft.EntityFrameworkCore.InMemory - 5.0.0-preview.3.20174.4 - Microsoft.EntityFrameworkCore.Relational - 5.0.0-preview.3.20174.4 - Microsoft.EntityFrameworkCore.Sqlite - 5.0.0-preview.3.20174.4 --- eng/Version.Details.xml | 28 ++++++++++++++-------------- eng/Versions.props | 14 +++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 34d0eb3d19a2..3c3ef37a59cb 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -29,33 +29,33 @@ https://github.com/dotnet/aspnetcore-tooling dcbab464643d971765e77562d2d0854c6ae112f7 - + https://github.com/dotnet/efcore - 9b1f0a0f11edf8a3ec4319493da46082f194dc33 + c9f9c33044a65a91ae47b13fcf3334b488e28891 - + https://github.com/dotnet/efcore - 9b1f0a0f11edf8a3ec4319493da46082f194dc33 + c9f9c33044a65a91ae47b13fcf3334b488e28891 - + https://github.com/dotnet/efcore - 9b1f0a0f11edf8a3ec4319493da46082f194dc33 + c9f9c33044a65a91ae47b13fcf3334b488e28891 - + https://github.com/dotnet/efcore - 9b1f0a0f11edf8a3ec4319493da46082f194dc33 + c9f9c33044a65a91ae47b13fcf3334b488e28891 - + https://github.com/dotnet/efcore - 9b1f0a0f11edf8a3ec4319493da46082f194dc33 + c9f9c33044a65a91ae47b13fcf3334b488e28891 - + https://github.com/dotnet/efcore - 9b1f0a0f11edf8a3ec4319493da46082f194dc33 + c9f9c33044a65a91ae47b13fcf3334b488e28891 - + https://github.com/dotnet/efcore - 9b1f0a0f11edf8a3ec4319493da46082f194dc33 + c9f9c33044a65a91ae47b13fcf3334b488e28891 https://github.com/dotnet/extensions diff --git a/eng/Versions.props b/eng/Versions.props index 734706e6b17c..983329c0cbbe 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -139,13 +139,13 @@ 5.0.0-preview.3.20170.1 5.0.0-preview.3.20170.1 - 5.0.0-preview.3.20174.3 - 5.0.0-preview.3.20174.3 - 5.0.0-preview.3.20174.3 - 5.0.0-preview.3.20174.3 - 5.0.0-preview.3.20174.3 - 5.0.0-preview.3.20174.3 - 5.0.0-preview.3.20174.3 + 5.0.0-preview.3.20174.4 + 5.0.0-preview.3.20174.4 + 5.0.0-preview.3.20174.4 + 5.0.0-preview.3.20174.4 + 5.0.0-preview.3.20174.4 + 5.0.0-preview.3.20174.4 + 5.0.0-preview.3.20174.4 5.0.0-preview.3.20170.3 5.0.0-preview.3.20170.3 From fd6a4ce8f5284f3de6b4ecf355914a3c6abc200d Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Tue, 24 Mar 2020 23:40:45 +0000 Subject: [PATCH 4/5] Update dependencies from https://github.com/dotnet/efcore build 20200324.5 - Microsoft.EntityFrameworkCore.Tools - 5.0.0-preview.3.20174.5 - Microsoft.EntityFrameworkCore.SqlServer - 5.0.0-preview.3.20174.5 - dotnet-ef - 5.0.0-preview.3.20174.5 - Microsoft.EntityFrameworkCore - 5.0.0-preview.3.20174.5 - Microsoft.EntityFrameworkCore.InMemory - 5.0.0-preview.3.20174.5 - Microsoft.EntityFrameworkCore.Relational - 5.0.0-preview.3.20174.5 - Microsoft.EntityFrameworkCore.Sqlite - 5.0.0-preview.3.20174.5 --- eng/Version.Details.xml | 28 ++++++++++++++-------------- eng/Versions.props | 14 +++++++------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 3c3ef37a59cb..9b3309ef46c9 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -29,33 +29,33 @@ https://github.com/dotnet/aspnetcore-tooling dcbab464643d971765e77562d2d0854c6ae112f7 - + https://github.com/dotnet/efcore - c9f9c33044a65a91ae47b13fcf3334b488e28891 + 21b9a35db594f7a383e855f922babbe54b3d38c5 - + https://github.com/dotnet/efcore - c9f9c33044a65a91ae47b13fcf3334b488e28891 + 21b9a35db594f7a383e855f922babbe54b3d38c5 - + https://github.com/dotnet/efcore - c9f9c33044a65a91ae47b13fcf3334b488e28891 + 21b9a35db594f7a383e855f922babbe54b3d38c5 - + https://github.com/dotnet/efcore - c9f9c33044a65a91ae47b13fcf3334b488e28891 + 21b9a35db594f7a383e855f922babbe54b3d38c5 - + https://github.com/dotnet/efcore - c9f9c33044a65a91ae47b13fcf3334b488e28891 + 21b9a35db594f7a383e855f922babbe54b3d38c5 - + https://github.com/dotnet/efcore - c9f9c33044a65a91ae47b13fcf3334b488e28891 + 21b9a35db594f7a383e855f922babbe54b3d38c5 - + https://github.com/dotnet/efcore - c9f9c33044a65a91ae47b13fcf3334b488e28891 + 21b9a35db594f7a383e855f922babbe54b3d38c5 https://github.com/dotnet/extensions diff --git a/eng/Versions.props b/eng/Versions.props index 983329c0cbbe..ef7259d692e0 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -139,13 +139,13 @@ 5.0.0-preview.3.20170.1 5.0.0-preview.3.20170.1 - 5.0.0-preview.3.20174.4 - 5.0.0-preview.3.20174.4 - 5.0.0-preview.3.20174.4 - 5.0.0-preview.3.20174.4 - 5.0.0-preview.3.20174.4 - 5.0.0-preview.3.20174.4 - 5.0.0-preview.3.20174.4 + 5.0.0-preview.3.20174.5 + 5.0.0-preview.3.20174.5 + 5.0.0-preview.3.20174.5 + 5.0.0-preview.3.20174.5 + 5.0.0-preview.3.20174.5 + 5.0.0-preview.3.20174.5 + 5.0.0-preview.3.20174.5 5.0.0-preview.3.20170.3 5.0.0-preview.3.20170.3 From a7d34727514b3f682502529f12b9163d4e83f481 Mon Sep 17 00:00:00 2001 From: AndriySvyryd Date: Tue, 24 Mar 2020 18:47:55 -0700 Subject: [PATCH 5/5] React to EF Migrations breaking changes --- .../src/DatabaseErrorPageMiddleware.cs | 28 ++++++++++++++++++- .../BloggingContextWithMigrations.cs | 27 ++++++++++-------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseErrorPageMiddleware.cs b/src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseErrorPageMiddleware.cs index ac2e913c24b9..8fea0d3ac110 100644 --- a/src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseErrorPageMiddleware.cs +++ b/src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseErrorPageMiddleware.cs @@ -13,6 +13,9 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Metadata.Conventions; +using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.Logging; @@ -138,13 +141,36 @@ public virtual async Task Invoke(HttpContext httpContext) var migrationsAssembly = context.GetService(); var modelDiffer = context.GetService(); + var snapshotModel = migrationsAssembly.ModelSnapshot?.Model; + if (snapshotModel is IConventionModel conventionModel) + { + var conventionSet = context.GetService().CreateConventionSet(); + + var typeMappingConvention = conventionSet.ModelFinalizingConventions.OfType().FirstOrDefault(); + if (typeMappingConvention != null) + { + typeMappingConvention.ProcessModelFinalizing(conventionModel.Builder, null); + } + + var relationalModelConvention = conventionSet.ModelFinalizedConventions.OfType().FirstOrDefault(); + if (relationalModelConvention != null) + { + snapshotModel = relationalModelConvention.ProcessModelFinalized(conventionModel); + } + } + + if (snapshotModel is IMutableModel mutableModel) + { + snapshotModel = mutableModel.FinalizeModel(); + } + // HasDifferences will return true if there is no model snapshot, but if there is an existing database // and no model snapshot then we don't want to show the error page since they are most likely targeting // and existing database and have just misconfigured their model var pendingModelChanges = (!databaseExists || migrationsAssembly.ModelSnapshot != null) - && modelDiffer.HasDifferences(migrationsAssembly.ModelSnapshot?.Model, context.Model); + && modelDiffer.HasDifferences(snapshotModel?.GetRelationalModel(), context.Model.GetRelationalModel()); var pendingMigrations = (databaseExists diff --git a/src/Middleware/Diagnostics.EntityFrameworkCore/test/FunctionalTests/TestModels/BloggingContextWithMigrations.cs b/src/Middleware/Diagnostics.EntityFrameworkCore/test/FunctionalTests/TestModels/BloggingContextWithMigrations.cs index f4ee82c93895..e1cf036793cf 100644 --- a/src/Middleware/Diagnostics.EntityFrameworkCore/test/FunctionalTests/TestModels/BloggingContextWithMigrations.cs +++ b/src/Middleware/Diagnostics.EntityFrameworkCore/test/FunctionalTests/TestModels/BloggingContextWithMigrations.cs @@ -21,25 +21,29 @@ public static BloggingContextWithMigrations CreateWithoutExternalServiceProvider return new BloggingContextWithMigrations(options); } + private static void BuildSnapshotModel(ModelBuilder builder) + { + builder.Entity("Blogging.Models.Blog", b => + { + b.Property("BlogId").ValueGeneratedOnAdd(); + b.Property("Name"); + b.HasKey("BlogId"); + }); + } + [DbContext(typeof(BloggingContextWithMigrations))] public class BloggingContextWithMigrationsModelSnapshot : ModelSnapshot { - protected override void BuildModel(ModelBuilder builder) - { - builder.Entity("Blogging.Models.Blog", b => - { - b.Property("BlogId").ValueGeneratedOnAdd(); - b.Property("Name"); - b.HasKey("BlogId"); - }); - } + protected override void BuildModel(ModelBuilder modelBuilder) + => BuildSnapshotModel(modelBuilder); } [DbContext(typeof(BloggingContextWithMigrations))] [Migration("111111111111111_MigrationOne")] public class MigrationOne : Migration { - public override IModel TargetModel => new BloggingContextWithMigrationsModelSnapshot().Model; + protected override void BuildTargetModel(ModelBuilder modelBuilder) + => BuildSnapshotModel(modelBuilder); protected override void Up(MigrationBuilder migrationBuilder) { @@ -62,7 +66,8 @@ protected override void Down(MigrationBuilder migrationBuilder) [Migration("222222222222222_MigrationTwo")] public class MigrationTwo : Migration { - public override IModel TargetModel => new BloggingContextWithMigrationsModelSnapshot().Model; + protected override void BuildTargetModel(ModelBuilder modelBuilder) + => BuildSnapshotModel(modelBuilder); protected override void Up(MigrationBuilder migrationBuilder) { }