Skip to content

Add TransactionMiddlewareMode for EF Core middleware#2160

Merged
jeremydmiller merged 1 commit intomainfrom
lightweight-ef-transaction
Feb 10, 2026
Merged

Add TransactionMiddlewareMode for EF Core middleware#2160
jeremydmiller merged 1 commit intomainfrom
lightweight-ef-transaction

Conversation

@jeremydmiller
Copy link
Member

Summary

  • Adds TransactionMiddlewareMode enum (Eager / Lightweight) to control whether EF Core transactional middleware opens an explicit database transaction or only relies on DbContext.SaveChangesAsync()
  • New UseEntityFrameworkCoreTransactions(TransactionMiddlewareMode) overload; existing no-arg version defaults to Eager for backwards compatibility
  • [Transactional(Mode = TransactionMiddlewareMode.Lightweight)] attribute property allows per-handler override of the global mode

Closes #2086

Test plan

  • eager_mode_should_add_transaction_frame — verifies Eager adds EnrollDbContextInTransaction
  • lightweight_mode_should_not_add_transaction_frame — verifies Lightweight skips transaction frame
  • default_mode_is_eager — verifies no-arg overload defaults to Eager
  • transactional_attribute_lightweight_overrides_eager_default — verifies attribute override from Eager→Lightweight
  • transactional_attribute_eager_overrides_lightweight_default — verifies attribute override from Lightweight→Eager
  • All 116/117 existing non-multi-tenancy EfCoreTests pass (1 pre-existing flaky failure unrelated)

🤖 Generated with Claude Code

…eware. Closes GH-2086

Introduces Eager vs Lightweight mode to control whether EF Core transactional
middleware opens an explicit database transaction or only relies on
DbContext.SaveChangesAsync(). Eager remains the default for backwards compatibility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Add An Alternative, Lighter EF Core Transactional Middleware Mode

1 participant