diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index f545658d93d0..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 - ac4633559b117b92156d75f07b7ef81dc920b4fd + 21b9a35db594f7a383e855f922babbe54b3d38c5 - + https://github.com/dotnet/efcore - ac4633559b117b92156d75f07b7ef81dc920b4fd + 21b9a35db594f7a383e855f922babbe54b3d38c5 - + https://github.com/dotnet/efcore - ac4633559b117b92156d75f07b7ef81dc920b4fd + 21b9a35db594f7a383e855f922babbe54b3d38c5 - + https://github.com/dotnet/efcore - ac4633559b117b92156d75f07b7ef81dc920b4fd + 21b9a35db594f7a383e855f922babbe54b3d38c5 - + https://github.com/dotnet/efcore - ac4633559b117b92156d75f07b7ef81dc920b4fd + 21b9a35db594f7a383e855f922babbe54b3d38c5 - + https://github.com/dotnet/efcore - ac4633559b117b92156d75f07b7ef81dc920b4fd + 21b9a35db594f7a383e855f922babbe54b3d38c5 - + https://github.com/dotnet/efcore - ac4633559b117b92156d75f07b7ef81dc920b4fd + 21b9a35db594f7a383e855f922babbe54b3d38c5 https://github.com/dotnet/extensions diff --git a/eng/Versions.props b/eng/Versions.props index 4d507eba31f7..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.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.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 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) { }