Skip to content

Commit

Permalink
Don't pull entity types from the context when building the Migrations…
Browse files Browse the repository at this point in the history
… history table

I think this is one of the root causes of the ASP.NET failures in dotnet/aspnetcore#10939 (comment)

The issue is that now that we discover DbSets from a context as a convention, re-using the convention-laden ModelBuilder for creating the history table also brings in types from the context.

For now, the fix is to remove this convention, but we may want to consider other options for building the history table.
  • Loading branch information
ajcvickers committed Jun 10, 2019
1 parent b62c28f commit 5f96030
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/EFCore.Relational/Migrations/HistoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore.Metadata.Conventions;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Utilities;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -92,8 +94,10 @@ private IModel EnsureModel()
{
if (_model == null)
{
var modelBuilder = new ModelBuilder(Dependencies.ConventionSetBuilder.CreateConventionSet());
var conventionSet = Dependencies.ConventionSetBuilder.CreateConventionSet();
ConventionSet.Remove(conventionSet.ModelInitializedConventions, typeof(DbSetFindingConvention));

var modelBuilder = new ModelBuilder(conventionSet);
modelBuilder.Entity<HistoryRow>(
x =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public MigrationsContext(DbContextOptions options)
: base(options)
{
}

public DbSet<Foo> Foos { get; set; }
}

public class Foo
{
public int Id { get; set; }
}

[DbContext(typeof(MigrationsContext))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ protected override async Task AssertFirstMigrationAsync(DbConnection connection)
Id int NOT NULL
ColumnWithDefaultToDrop int NULL DEFAULT ((0))
ColumnWithDefaultToAlter int NULL DEFAULT ((1))
Foos
Id int NOT NULL
",
sql,
ignoreLineEndingDifferences: true);
Expand All @@ -372,6 +375,9 @@ protected override async Task AssertSecondMigrationAsync(DbConnection connection
CreatedTable
Id int NOT NULL
ColumnWithDefaultToAlter int NULL
Foos
Id int NOT NULL
",
sql,
ignoreLineEndingDifferences: true);
Expand Down
14 changes: 14 additions & 0 deletions test/EFCore.Sqlite.FunctionalTests/MigrationsSqliteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ protected override void AssertFirstMigration(DbConnection connection)
Id INTEGER NOT NULL
ColumnWithDefaultToDrop INTEGER NULL DEFAULT 0
ColumnWithDefaultToAlter INTEGER NULL DEFAULT 1
Foos
Id INTEGER NOT NULL
sqlite_sequence
name NULL
seq NULL
",
sql,
ignoreLineEndingDifferences: true);
Expand Down Expand Up @@ -214,6 +221,13 @@ protected override void AssertSecondMigration(DbConnection connection)
Id INTEGER NOT NULL
ColumnWithDefaultToDrop INTEGER NULL DEFAULT 0
ColumnWithDefaultToAlter INTEGER NULL DEFAULT 1
Foos
Id INTEGER NOT NULL
sqlite_sequence
name NULL
seq NULL
",
sql,
ignoreLineEndingDifferences: true);
Expand Down

0 comments on commit 5f96030

Please sign in to comment.