Emit all properties on the join type, even when there's no extra configuration#37783
Merged
AndriySvyryd merged 1 commit intomainfrom Feb 24, 2026
Merged
Emit all properties on the join type, even when there's no extra configuration#37783AndriySvyryd merged 1 commit intomainfrom
AndriySvyryd merged 1 commit intomainfrom
Conversation
…iguration on them. Fixes #35524
3a3467a to
d8a41aa
Compare
There was a problem hiding this comment.
Pull request overview
This pull request fixes issue #35524 where scaffolding a many-to-many relationship with a composite foreign key containing 3 or more properties would omit properties from the generated OnModelCreating code if they had no extra fluent API configuration. This resulted in runtime errors due to incompatible foreign key types.
Changes:
- Modified the T4 template logic in
CSharpDbContextGenerator.ttto emitIndexerPropertycalls for all properties in join entity types, regardless of whether they have additional fluent API configuration - Added comprehensive test coverage for the scenario with composite foreign keys in many-to-many relationships
- Updated existing test baselines to reflect that all join entity properties are now emitted
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.tt |
Fixed the logic to emit IndexerProperty for all join entity properties, not just those with extra configuration |
src/EFCore.Design/Scaffolding/Internal/CSharpDbContextGenerator.cs |
Generated C# code from the T4 template reflecting the fix |
test/EFCore.Design.Tests/Scaffolding/Internal/RelationalScaffoldingModelFactoryTest.cs |
Added test to verify model scaffolding with composite foreign keys in many-to-many relationships |
test/EFCore.Design.Tests/Scaffolding/Internal/CSharpEntityTypeGeneratorTest.cs |
Added comprehensive code generation test and updated baselines for existing tests to include all IndexerProperty calls |
roji
approved these changes
Feb 24, 2026
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.
Fixes #35524
When scaffolding a many-to-many relationship where the join table has a composite foreign key with 3 or more properties, the generated OnModelCreating code can omit one of them if it had no extra fluent API configuration.