Skip to content

Fix TPH topological sort when base class has FK dependency#229

Merged
jeremydmiller merged 1 commit into
masterfrom
fix-tph-topological-sort-228
Mar 27, 2026
Merged

Fix TPH topological sort when base class has FK dependency#229
jeremydmiller merged 1 commit into
masterfrom
fix-tph-topological-sort-228

Conversation

@jeremydmiller

Copy link
Copy Markdown
Member

Summary

  • Fixes EF Core Migration order dependency incorrect with TPH #228: EF Core migration order dependency incorrect with TPH
  • When a TPH base class has a FK, derived types inherit the same FK, causing duplicate dependency edges in the topological sort. This inflates in-degree counts in Kahn's algorithm but only decrements once, triggering false cycle detection and returning unsorted results
  • Fix: use HashSet<IEntityType> instead of List<IEntityType> for dependency edges to deduplicate
  • Bumps Weasel version to 8.10.3

Test plan

  • Added entity_types_sorted_correctly_when_base_class_has_fk test that reproduces the issue (fails without fix, passes with fix)
  • Added can_apply_migration_when_base_class_has_fk integration test
  • Existing TPH and FK ordering tests continue to pass

🤖 Generated with Claude Code

When a TPH base class has a foreign key, derived types inherit the same FK,
causing duplicate dependency edges in the topological sort. This inflates
in-degree counts in Kahn's algorithm but only decrements once, triggering
false cycle detection and returning unsorted results.

Fix: use HashSet instead of List for dependency edges to deduplicate.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jeremydmiller jeremydmiller merged commit de50d44 into master Mar 27, 2026
21 checks passed
@jeremydmiller jeremydmiller deleted the fix-tph-topological-sort-228 branch March 27, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EF Core Migration order dependency incorrect with TPH

1 participant