Skip to content

[release/11.0] Allow unconstrained relationships to break SaveChanges command cycles - #38989

Open
AndriySvyryd with Copilot wants to merge 3 commits into
release/11.0from
copilot/fix-circular-dependency-savechanges
Open

AndriySvyryd with Copilot wants to merge 3 commits into
release/11.0from
copilot/fix-circular-dependency-savechanges

Conversation

Copilot AI commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #38978

Description
Relationships configured with IsConstrained(false) were treated as mandatory SaveChanges command dependencies, causing false circular-dependency errors despite having no database constraint. The change makes an unconstrained foreign-key edge breakable only when it does not require a store-generated-value batching boundary.

Customer impact
Affected applications cannot persist otherwise valid graphs containing an unconstrained reverse relationship in one SaveChanges call; EF Core throws a circular-dependency exception. A workaround is to persist the entities in separate operations or avoid the cyclic relationship configuration.

How found
Customer reported in #38978. The number of affected customers is unknown.

Regression
No, unconstrained relationships are a new feature in EF 11

Testing
Tests added.

Risk
Low. The behavior is limited to unconstrained relationships.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix false circular dependency during SaveChanges with IsConstrained(false) Allow unconstrained relationships to break SaveChanges command cycles Sep 14, 2026
Copilot AI requested a review from AndriySvyryd September 14, 2026 18:23
@AndriySvyryd
AndriySvyryd requested a balanced review from Copilot September 14, 2026 19:57
@AndriySvyryd

Copy link
Copy Markdown
Member

@copilot Update progress by rewriting the PR summary using this template:

Fixes #{number}

**Description**
{Issue description}

**Customer impact**
{How does the reported issue affects customer's app? Are there workarounds?}

**How found**
{Was it customer reported or found during verification? How many customers are affected?}

**Regression**
{Is it a regression from a released version? Which one?}

**Testing**
{How the changes were tested}

**Risk**
{Low/Medium/High, argument why}

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The generated-key boundary guard lacks direct regression coverage.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Allows unconstrained foreign-key dependencies to break SaveChanges command cycles while preserving generated-key batching boundaries.

Changes:

  • Marks eligible unconstrained FK graph edges as breakable.
  • Adds regression coverage for cyclic insert ordering.
File summaries
File Description
CommandBatchPreparer.cs Updates dependency-edge breakability.
CommandBatchPreparerTest.cs Tests unconstrained cycle resolution.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread src/EFCore.Relational/Update/Internal/CommandBatchPreparer.cs

Copilot AI commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Update progress by rewriting the PR summary using this template:

...

Updated the PR summary using the requested template, including #38978 and the implementation, impact, testing, and risk details.

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
@AndriySvyryd AndriySvyryd changed the title Allow unconstrained relationships to break SaveChanges command cycles [release/11.0] Allow unconstrained relationships to break SaveChanges command cycles Sep 14, 2026
@AndriySvyryd
AndriySvyryd marked this pull request as ready for review September 14, 2026 20:50
@AndriySvyryd
AndriySvyryd requested a review from a team as a code owner September 14, 2026 20:50
Copilot AI review requested due to automatic review settings September 14, 2026 20:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused implementation matches the required semantics and covers both key paths.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

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.

IsConstrained(false) relationship causes false circular dependency during SaveChanges

3 participants