Skip to content

Commit

Permalink
Fix migrations for index included properties
Browse files Browse the repository at this point in the history
This failed when the column name wasn't the same as the property
name.

Fixes #1201
Same as dotnet/efcore#14087 for SQL Server.
  • Loading branch information
roji committed Jan 23, 2020
1 parent 056a88d commit b8f879b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ public override IEnumerable<IAnnotation> For(IIndex index)
if (index.GetNullSortOrder() is IReadOnlyList<SortOrder> nullSortOrder)
yield return new Annotation(NpgsqlAnnotationNames.IndexNullSortOrder, nullSortOrder);
if (index.GetIncludeProperties() is IReadOnlyList<string> includeProperties)
yield return new Annotation(NpgsqlAnnotationNames.IndexInclude, includeProperties);
{
var includeColumns = (IReadOnlyList<string>)includeProperties
.Select(p => index.DeclaringEntityType.FindProperty(p).GetColumnName())
.ToArray();

yield return new Annotation(
NpgsqlAnnotationNames.IndexInclude,
includeColumns);
}

var isCreatedConcurrently = index.IsCreatedConcurrently();
if (isCreatedConcurrently.HasValue)
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.PG/Migrations/NpgsqlMigrationsSqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,11 +670,11 @@ protected override void Generate(

protected override void IndexOptions(CreateIndexOperation operation, IModel model, MigrationCommandListBuilder builder)
{
if (operation[NpgsqlAnnotationNames.IndexInclude] is string[] includeProperties && includeProperties.Length > 0)
if (operation[NpgsqlAnnotationNames.IndexInclude] is string[] includeColumns && includeColumns.Length > 0)
{
builder
.Append(" INCLUDE (")
.Append(ColumnList(includeProperties))
.Append(ColumnList(includeColumns))
.Append(")");
}

Expand Down

0 comments on commit b8f879b

Please sign in to comment.