Reacting to EF change
This commit is contained in:
parent
44b50b46f9
commit
6f8407bca4
|
|
@ -8,10 +8,12 @@ using Microsoft.AspNet.Diagnostics.Entity.Views;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.RequestContainer;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Data.Entity.Infrastructure;
|
||||
using Microsoft.Data.Entity.Migrations;
|
||||
using Microsoft.Data.Entity.Migrations.Infrastructure;
|
||||
using Microsoft.Data.Entity.Migrations.Utilities;
|
||||
using Microsoft.Data.Entity.Relational;
|
||||
using Microsoft.Data.Entity.Utilities;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Logging;
|
||||
using System;
|
||||
|
|
@ -81,15 +83,17 @@ namespace Microsoft.AspNet.Diagnostics.Entity
|
|||
{
|
||||
var databaseExists = dbContext.Database.AsRelational().Exists();
|
||||
|
||||
var services = (MigrationsDataStoreServices)dbContext.Configuration.DataStoreServices;
|
||||
var contextServices = ((IDbContextServices)dbContext).ScopedServiceProvider;
|
||||
var services = (MigrationsDataStoreServices)contextServices.GetRequiredService<DbContextConfiguration>().DataStoreServices;
|
||||
var migrator = services.Migrator;
|
||||
|
||||
var pendingMigrations = services.Migrator.GetPendingMigrations().Select(m => m.GetMigrationId());
|
||||
var pendingMigrations = migrator.GetPendingMigrations().Select(m => m.GetMigrationId());
|
||||
|
||||
var pendingModelChanges = true;
|
||||
var snapshot = services.Migrator.MigrationAssembly.Model;
|
||||
var snapshot = migrator.MigrationAssembly.Model;
|
||||
if (snapshot != null)
|
||||
{
|
||||
pendingModelChanges = services.Migrator.ModelDiffer.Diff(snapshot, dbContext.Model).Any();
|
||||
pendingModelChanges = migrator.ModelDiffer.Diff(snapshot, dbContext.Model).Any();
|
||||
}
|
||||
|
||||
if ((!databaseExists && pendingMigrations.Any()) || pendingMigrations.Any() || pendingModelChanges)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ using Microsoft.AspNet.Diagnostics.Entity.FunctionalTests.Helpers;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Data.Entity.Infrastructure;
|
||||
using Microsoft.Data.Entity.Migrations.Infrastructure;
|
||||
using Microsoft.Data.Entity.Utilities;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Logging;
|
||||
using Xunit;
|
||||
|
|
@ -157,7 +159,8 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
{
|
||||
using (var db = context.ApplicationServices.GetService<BloggingContextWithPendingModelChanges>())
|
||||
{
|
||||
var services = (MigrationsDataStoreServices)db.Configuration.DataStoreServices;
|
||||
var contextServices = ((IDbContextServices)db).ScopedServiceProvider;
|
||||
var services = (MigrationsDataStoreServices)contextServices.GetRequiredService<DbContextConfiguration>().DataStoreServices;
|
||||
services.Migrator.ApplyMigrations();
|
||||
|
||||
db.Blogs.Add(new Blog());
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ using Microsoft.AspNet.Builder;
|
|||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.TestHost;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Data.Entity.Infrastructure;
|
||||
using Microsoft.Data.Entity.Migrations.Infrastructure;
|
||||
using Microsoft.Data.Entity.Migrations.Utilities;
|
||||
using Microsoft.Data.Entity.Utilities;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Xunit;
|
||||
using Microsoft.AspNet.Diagnostics.Entity.Tests.Helpers;
|
||||
|
|
@ -99,8 +101,9 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests
|
|||
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
|
||||
|
||||
Assert.True(db.Database.AsRelational().Exists());
|
||||
var services = (MigrationsDataStoreServices)db.Configuration.DataStoreServices;
|
||||
var appliedMigrations = services.Migrator.GetDatabaseMigrations();
|
||||
var contextServices = ((IDbContextServices)db).ScopedServiceProvider;
|
||||
var dataStoreServices = (MigrationsDataStoreServices)contextServices.GetRequiredService<DbContextConfiguration>().DataStoreServices;
|
||||
var appliedMigrations = dataStoreServices.Migrator.GetDatabaseMigrations();
|
||||
Assert.Equal(2, appliedMigrations.Count);
|
||||
Assert.Equal("111111111111111_MigrationOne", appliedMigrations.ElementAt(0).GetMigrationId());
|
||||
Assert.Equal("222222222222222_MigrationTwo", appliedMigrations.ElementAt(1).GetMigrationId());
|
||||
|
|
|
|||
Loading…
Reference in New Issue