Skip to content

Commit

Permalink
Don't remove skip foreign key when join entity type is configured exp…
Browse files Browse the repository at this point in the history
…licitly. (#22652)

Fixes #22521
  • Loading branch information
AndriySvyryd committed Sep 22, 2020
1 parent 79ebfdd commit 3a1fd2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/EFCore/Metadata/Conventions/ModelCleanupConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ private void RemoveNavigationlessForeignKeys(IConventionModelBuilder modelBuilde
foreach (var foreignKey in entityType.GetDeclaredForeignKeys().ToList())
{
if (foreignKey.PrincipalToDependent == null
&& foreignKey.DependentToPrincipal == null)
&& foreignKey.DependentToPrincipal == null
&& !foreignKey.GetReferencingSkipNavigations().Any())
{
entityType.Builder.HasNoRelationship(foreignKey, fromDataAnnotation: true);
}
Expand Down
6 changes: 5 additions & 1 deletion test/EFCore.Tests/ModelBuilding/ManyToManyTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public virtual void Discovers_navigations()
modelBuilder.Entity<Product>();
modelBuilder.Entity<CategoryBase>();

var sharedTypeName = nameof(Category) + nameof(Product);

modelBuilder.SharedTypeEntity<Dictionary<string, object>>(sharedTypeName);

var model = modelBuilder.FinalizeModel();

var productType = model.FindEntityType(typeof(Product));
Expand All @@ -39,7 +43,7 @@ public virtual void Discovers_navigations()
var productCategoryType = categoriesFk.DeclaringEntityType;

Assert.Equal(typeof(Dictionary<string, object>), productCategoryType.ClrType);
Assert.Equal(nameof(Category) + nameof(Product), productCategoryType.Name);
Assert.Equal(sharedTypeName, productCategoryType.Name);
Assert.Same(categoriesFk, productCategoryType.GetForeignKeys().Last());
Assert.Same(productsFk, productCategoryType.GetForeignKeys().First());
Assert.Equal(2, productCategoryType.GetForeignKeys().Count());
Expand Down

0 comments on commit 3a1fd2d

Please sign in to comment.