Scaffolding fails for a self-referencing many-to-many join table when both FKs yield the same navigation name - #38787
Open
ilkertskn wants to merge 2 commits into
Conversation
…ny-to-many join table - The name generated for the left skip navigation was neither added to the existing identifiers nor present in the model when the right name was generated, and the identifier list is shared by both ends when the join table references a single entity type, so the uniquifier produced the same name twice and AddSkipNavigation threw, failing the whole scaffolding operation - Add the generated name to the identifiers so the right-hand side sees it - Add a test for a self-referencing join table whose foreign keys yield the same candidate name
Contributor
Author
|
@dotnet-policy-service agree |
There was a problem hiding this comment.
Pull request overview
Fixes a reverse-engineering/scaffolding failure for self-referencing many-to-many join tables where both skip navigations end up with the same generated name, causing AddSkipNavigation to throw and scaffolding to fail.
Changes:
- Ensures the left skip-navigation name is added to the existing identifier set before generating the right skip-navigation name (preventing duplicate-name generation in self-referencing join scenarios).
- Adds a new regression test intended to cover colliding skip-navigation names on a self-referencing join table.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/EFCore.Design/Scaffolding/Internal/RelationalScaffoldingModelFactory.cs | Makes the left skip-navigation name visible to subsequent naming to avoid collisions when both ends share the same identifier list. |
| test/EFCore.Design.Tests/Scaffolding/Internal/RelationalScaffoldingModelFactoryTest.cs | Adds a regression test for self-referencing many-to-many join-table skip-navigation name collisions. |
Suppressed comments (1)
test/EFCore.Design.Tests/Scaffolding/Internal/RelationalScaffoldingModelFactoryTest.cs:2734
- The assertions only check for uniqueness, which could still pass if the candidate names don’t collide (or if the uniquifier changes behavior). Tightening this to assert the expected collision resolution (e.g.
ProductsandProductsNavigation) makes the regression coverage more direct and stable.
Assert.Equal(2, skipNavigationNames.Count);
Assert.Equal(skipNavigationNames.Count, skipNavigationNames.Distinct().Count());
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.