Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extra ToList calls in MigrationsModelDiffer #22471

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ protected virtual IReadOnlyList<MigrationOperation> Sort(
}
}

createTableOperations = createTableGraph.TopologicalSort(
createTableOperations = (List<CreateTableOperation>)createTableGraph.TopologicalSort(
(principalCreateTableOperation, createTableOperation, cyclicAddForeignKeyOperations) =>
{
foreach (var cyclicAddForeignKeyOperation in cyclicAddForeignKeyOperations)
Expand All @@ -321,7 +321,7 @@ protected virtual IReadOnlyList<MigrationOperation> Sort(
}

return true;
}).ToList();
});

var dropTableGraph = new Multigraph<DropTableOperation, IForeignKeyConstraint>();
dropTableGraph.AddVertices(dropTableOperations);
Expand All @@ -340,13 +340,13 @@ protected virtual IReadOnlyList<MigrationOperation> Sort(
}

var newDiffContext = new DiffContext();
dropTableOperations = dropTableGraph.TopologicalSort(
dropTableOperations = (List<DropTableOperation>)dropTableGraph.TopologicalSort(
(dropTableOperation, principalDropTableOperation, foreignKeys) =>
{
dropForeignKeyOperations.AddRange(foreignKeys.SelectMany(c => Remove(c, newDiffContext)));

return true;
}).ToList();
});

return dropForeignKeyOperations
.Concat(dropTableOperations)
Expand Down Expand Up @@ -429,7 +429,6 @@ private IEnumerable<MigrationOperation> DiffAnnotations(
IRelationalModel source,
IRelationalModel target)
{
var sourceMigrationsAnnotations = source?.GetAnnotations().ToList();
var targetMigrationsAnnotations = target?.GetAnnotations().ToList();

if (source == null)
Expand All @@ -446,17 +445,18 @@ private IEnumerable<MigrationOperation> DiffAnnotations(

if (target == null)
{
sourceMigrationsAnnotations = MigrationsAnnotations.ForRemove(source).ToList();
if (sourceMigrationsAnnotations.Count > 0)
var sourceMigrationsAnnotationsForRemoved = MigrationsAnnotations.ForRemove(source).ToList();
if (sourceMigrationsAnnotationsForRemoved.Count > 0)
{
var alterDatabaseOperation = new AlterDatabaseOperation();
alterDatabaseOperation.OldDatabase.AddAnnotations(sourceMigrationsAnnotations);
alterDatabaseOperation.OldDatabase.AddAnnotations(sourceMigrationsAnnotationsForRemoved);
yield return alterDatabaseOperation;
}

yield break;
}

var sourceMigrationsAnnotations = source?.GetAnnotations().ToList();
if (HasDifferences(sourceMigrationsAnnotations, targetMigrationsAnnotations))
{
var alterDatabaseOperation = new AlterDatabaseOperation();
Expand Down