Skip to content

Comments

Emit all properties on the join type, even when there's no extra configuration#37783

Merged
AndriySvyryd merged 1 commit intomainfrom
Issue35524
Feb 24, 2026
Merged

Emit all properties on the join type, even when there's no extra configuration#37783
AndriySvyryd merged 1 commit intomainfrom
Issue35524

Conversation

@AndriySvyryd
Copy link
Member

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.

@AndriySvyryd AndriySvyryd requested a review from a team as a code owner February 24, 2026 05:20
Copilot AI review requested due to automatic review settings February 24, 2026 05:20
@AndriySvyryd AndriySvyryd changed the title [release/10.0] Emit all properties on the join type, even when there's no extra configuration Emit all properties on the join type, even when there's no extra configuration Feb 24, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.tt to emit IndexerProperty calls 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

@AndriySvyryd AndriySvyryd merged commit 8a06ad4 into main Feb 24, 2026
13 checks passed
@AndriySvyryd AndriySvyryd deleted the Issue35524 branch February 24, 2026 18:32
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.

DbContext scaffold missing IndexerProperty for M2M relation after upgrading from EF Core 6 to EF Core 8

2 participants