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

[6.0.1] RevEng: Consider skip navigation names when generating identifier for members of class #26531

Merged
merged 1 commit into from
Nov 9, 2021
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 @@ -1003,6 +1003,11 @@ protected virtual List<string> ExistingIdentifiers(IReadOnlyEntityType entityTyp
}

existingIdentifiers.AddRange(entityType.GetNavigations().Select(p => p.Name));
if (!(AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue26496", out var enabled)
&& enabled))
{
existingIdentifiers.AddRange(entityType.GetSkipNavigations().Select(p => p.Name));
}
return existingIdentifiers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2256,5 +2256,122 @@ public void Scaffold_skip_navigation_for_many_to_many_join_table_basic()
});

}

[ConditionalFact]
public void Scaffold_skip_navigation_for_many_to_many_join_table_self_ref()
{
var database = new DatabaseModel
{
Tables =
{
new DatabaseTable
{
Name = "Products",
Columns =
{
new DatabaseColumn
{
Name = "Id",
StoreType = "int"
}
},
PrimaryKey = new DatabasePrimaryKey { Columns = { new DatabaseColumnRef("Id") } }
},
new DatabaseTable
{
Name = "RelatedProducts",
Columns =
{
new DatabaseColumn
{
Name = "Id",
StoreType = "int"
},
new DatabaseColumn
{
Name = "ProductId",
StoreType = "int"
}
},
PrimaryKey = new DatabasePrimaryKey {
Columns = { new DatabaseColumnRef("Id"), new DatabaseColumnRef("ProductId") } },
ForeignKeys =
{
new DatabaseForeignKey
{
Columns = { new DatabaseColumnRef("Id") },
PrincipalColumns = { new DatabaseColumnRef("Id") },
PrincipalTable = new DatabaseTableRef("Products"),
},
new DatabaseForeignKey
{
Columns = { new DatabaseColumnRef("ProductId") },
PrincipalColumns = { new DatabaseColumnRef("Id") },
PrincipalTable = new DatabaseTableRef("Products"),
}
}
},
new DatabaseTable
{
Name = "SubProducts",
Columns =
{
new DatabaseColumn
{
Name = "Id",
StoreType = "int"
},
new DatabaseColumn
{
Name = "ProductId",
StoreType = "int"
}
},
PrimaryKey = new DatabasePrimaryKey {
Columns = { new DatabaseColumnRef("Id"), new DatabaseColumnRef("ProductId") } },
ForeignKeys =
{
new DatabaseForeignKey
{
Columns = { new DatabaseColumnRef("Id") },
PrincipalColumns = { new DatabaseColumnRef("Id") },
PrincipalTable = new DatabaseTableRef("Products"),
},
new DatabaseForeignKey
{
Columns = { new DatabaseColumnRef("ProductId") },
PrincipalColumns = { new DatabaseColumnRef("Id") },
PrincipalTable = new DatabaseTableRef("Products"),
}
}
}
}
};

var model = _factory.Create(database, new ModelReverseEngineerOptions());

Assert.Collection(
model.GetEntityTypes().OrderBy(e => e.Name),
t1 =>
{
Assert.Empty(t1.GetNavigations());
Assert.Collection(t1.GetSkipNavigations(),
s => Assert.Equal("Ids", s.Name),
s => Assert.Equal("IdsNavigation", s.Name),
s => Assert.Equal("Products", s.Name),
s => Assert.Equal("ProductsNavigation", s.Name));
},
t2 =>
{
Assert.Empty(t2.GetNavigations());
Assert.Equal(2, t2.GetForeignKeys().Count());
},
t2 =>
{
Assert.Empty(t2.GetNavigations());
Assert.Equal(2, t2.GetForeignKeys().Count());
});

}
}
}