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

[release/5.0] SqlServer RevEng: Stop scaffolding included index columns #23083

Merged
merged 1 commit into from
Oct 24, 2020
Merged
Show file tree
Hide file tree
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 @@ -1005,17 +1005,13 @@ FROM [sys].[indexes] i
index[SqlServerAnnotationNames.FillFactor] = indexGroup.Key.FillFactor;
}

var includedColumns = new List<string>();

foreach (var dataRecord in indexGroup)
{
var columnName = dataRecord.GetValueOrDefault<string>("column_name");

var isIncludedColumn = dataRecord.GetValueOrDefault<bool>("is_included_column");
if (isIncludedColumn)
{
includedColumns.Add(columnName!);

continue;
}

Expand All @@ -1027,11 +1023,6 @@ FROM [sys].[indexes] i
index.Columns.Add(column);
}

if (includedColumns.Count != 0)
{
index[SqlServerAnnotationNames.Include] = includedColumns.ToArray();
}

table.Indexes.Add(index);
}
}
Expand Down
34 changes: 9 additions & 25 deletions test/EFCore.SqlServer.FunctionalTests/MigrationsSqlServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,7 @@ await Test(
Assert.Equal(1, index.Columns.Count);
Assert.Contains(table.Columns.Single(c => c.Name == "SomeColumn"), index.Columns);
var includedColumns = (IReadOnlyList<string>)index[SqlServerAnnotationNames.Include];
Assert.Equal(1, includedColumns.Count);
Assert.Contains("SomeOtherColumn", includedColumns);
Assert.Null(includedColumns);
});

AssertSql(
Expand Down Expand Up @@ -853,8 +852,7 @@ await Test(
Assert.Contains(table.Columns.Single(c => c.Name == "FirstName"), index.Columns);
Assert.Contains(table.Columns.Single(c => c.Name == "LastName"), index.Columns);
var includedColumns = (IReadOnlyList<string>)index[SqlServerAnnotationNames.Include];
Assert.Equal(1, includedColumns.Count);
Assert.Contains("Name", includedColumns);
Assert.Null(includedColumns);
});

AssertSql(
Expand Down Expand Up @@ -1135,9 +1133,7 @@ await Test(
Assert.Equal(1, index.Columns.Count);
Assert.Contains(table.Columns.Single(c => c.Name == "Name"), index.Columns);
var includedColumns = (IReadOnlyList<string>)index[SqlServerAnnotationNames.Include];
Assert.Equal(2, includedColumns.Count);
Assert.Contains("FirstName", includedColumns);
Assert.Contains("LastName", includedColumns);
Assert.Null(includedColumns);
});

AssertSql(
Expand Down Expand Up @@ -1176,9 +1172,7 @@ await Test(
Assert.Equal(1, index.Columns.Count);
Assert.Contains(table.Columns.Single(c => c.Name == "Name"), index.Columns);
var includedColumns = (IReadOnlyList<string>)index[SqlServerAnnotationNames.Include];
Assert.Equal(2, includedColumns.Count);
Assert.Contains("FirstName", includedColumns);
Assert.Contains("LastName", includedColumns);
Assert.Null(includedColumns);
});

AssertSql(
Expand Down Expand Up @@ -1217,9 +1211,7 @@ await Test(
Assert.Equal(1, index.Columns.Count);
Assert.Contains(table.Columns.Single(c => c.Name == "Name"), index.Columns);
var includedColumns = (IReadOnlyList<string>)index[SqlServerAnnotationNames.Include];
Assert.Equal(2, includedColumns.Count);
Assert.Contains("FirstName", includedColumns);
Assert.Contains("LastName", includedColumns);
Assert.Null(includedColumns);
});

AssertSql(
Expand Down Expand Up @@ -1260,9 +1252,7 @@ await Test(
Assert.Equal(1, index.Columns.Count);
Assert.Contains(table.Columns.Single(c => c.Name == "Name"), index.Columns);
var includedColumns = (IReadOnlyList<string>)index[SqlServerAnnotationNames.Include];
Assert.Equal(2, includedColumns.Count);
Assert.Contains("FirstName", includedColumns);
Assert.Contains("LastName", includedColumns);
Assert.Null(includedColumns);
});

AssertSql(
Expand Down Expand Up @@ -1305,9 +1295,7 @@ await Test(
Assert.Equal(1, index.Columns.Count);
Assert.Contains(table.Columns.Single(c => c.Name == "Name"), index.Columns);
var includedColumns = (IReadOnlyList<string>)index[SqlServerAnnotationNames.Include];
Assert.Equal(2, includedColumns.Count);
Assert.Contains("FirstName", includedColumns);
Assert.Contains("LastName", includedColumns);
Assert.Null(includedColumns);
// TODO: Online index not scaffolded?
});

Expand Down Expand Up @@ -1352,9 +1340,7 @@ await Test(
Assert.Equal(1, index.Columns.Count);
Assert.Contains(table.Columns.Single(c => c.Name == "Name"), index.Columns);
var includedColumns = (IReadOnlyList<string>)index[SqlServerAnnotationNames.Include];
Assert.Equal(2, includedColumns.Count);
Assert.Contains("FirstName", includedColumns);
Assert.Contains("LastName", includedColumns);
Assert.Null(includedColumns);
// TODO: Online index not scaffolded?
});

Expand Down Expand Up @@ -1397,9 +1383,7 @@ await Test(
Assert.Equal(1, index.Columns.Count);
Assert.Contains(table.Columns.Single(c => c.Name == "Name"), index.Columns);
var includedColumns = (IReadOnlyList<string>)index[SqlServerAnnotationNames.Include];
Assert.Equal(2, includedColumns.Count);
Assert.Contains("FirstName", includedColumns);
Assert.Contains("LastName", includedColumns);
Assert.Null(includedColumns);
// TODO: Online index not scaffolded?
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1929,7 +1929,7 @@ IncludeProperty int
{
var index = Assert.Single(dbModel.Tables.Single().Indexes);
Assert.Equal(new[] { "IndexProperty" }, index.Columns.Select(ic => ic.Name).ToList());
Assert.Equal(new[] { "IncludeProperty" }, (IReadOnlyList<string>)index[SqlServerAnnotationNames.Include]);
Assert.Null(index[SqlServerAnnotationNames.Include]);
},
"DROP TABLE IncludeIndexTable;");
}
Expand Down