Skip to content
Open
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 @@ -707,6 +707,10 @@ protected virtual ModelBuilder VisitForeignKeys(
singularizePluralizer: null,
uniquifier: NavigationUniquifier);

// The skip navigation is only added to the model below, so make the name visible to the right-hand
// side, which otherwise generates the same name when the join table references a single entity type.
leftExistingIdentifiers.Add(leftNavigationPropertyName);

var rightExistingIdentifiers = ExistingIdentifiers(rightEntityType);
var rightNavigationPropertyCandidateName =
_candidateNamingService.GetDependentEndCandidateNavigationPropertyName(fks[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2681,6 +2681,59 @@ public void Scaffold_skip_navigation_for_many_to_many_join_table_self_ref()
});
}

[Fact]
public void Scaffold_skip_navigation_for_many_to_many_join_table_self_ref_with_colliding_navigation_names()
{
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 = "Product_Id", StoreType = "int" },
new DatabaseColumn { Name = "ProductId", StoreType = "int" }
},
PrimaryKey = new DatabasePrimaryKey
{
Columns = { new DatabaseColumnRef("Product_Id"), new DatabaseColumnRef("ProductId") }
},
ForeignKeys =
{
new DatabaseForeignKey
{
Columns = { new DatabaseColumnRef("Product_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());

var product = model.GetEntityTypes().Single(e => e.Name == "Product");
var skipNavigationNames = product.GetSkipNavigations().Select(n => n.Name).ToList();

Assert.Equal(2, skipNavigationNames.Count);
Assert.Equal(skipNavigationNames.Count, skipNavigationNames.Distinct().Count());
}

[Fact]
public void Scaffold_skip_navigation_for_many_to_many_join_table_composite_fk()
{
Expand Down
Loading