feat: support serialized SaveChanges overrides - #10
Merged
CornerstoneCode merged 2 commits intoJul 21, 2026
Merged
Conversation
📝 WalkthroughWalkthrough
ChangesSerialized Save Override
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ConcurrentWriters
participant OverrideSaveChangesDbContext
participant SaveChangesSerializedAsync
participant SQLite
ConcurrentWriters->>OverrideSaveChangesDbContext: call SaveChangesAsync
OverrideSaveChangesDbContext->>SaveChangesSerializedAsync: pass base save delegate
SaveChangesSerializedAsync->>SQLite: serialize and persist changes
SQLite-->>ConcurrentWriters: return saved data
ConcurrentWriters->>SQLite: verify final entity count
SQLite-->>ConcurrentWriters: return expected total
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
CornerstoneCode
approved these changes
Jul 21, 2026
Dutchevil
pushed a commit
to Dutchevil/Reaparr
that referenced
this pull request
Jul 22, 2026
Contributor
Author
|
@CornerstoneCode thanks for the merge, could you publish a new release? |
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.
Type of Change
Summary
This PR adds a delegate-based overload for
SaveChangesSerializedAsyncso applications can safely serialize allDbContext.SaveChangesAsync(...)calls from inside aDbContextoverride.The existing
SaveChangesSerializedAsync(this DbContext context, ...)API works well when call sites explicitly opt in:However, it cannot currently be used to make serialization automatic at the
DbContextlevel:That override causes infinite recursion because
SaveChangesSerializedAsyncinternally callscontext.SaveChangesAsync(...), which re-enters the override.This PR fixes that by adding an overload that accepts the actual save operation as a delegate:
Consumers can now safely write:
Why this is useful
Some applications want SQLite write serialization to be a database-context invariant rather than a call-site convention.
Without this change, every write path must remember to call:
instead of:
That is easy to miss in larger applications, especially when writes happen across:
A missed call site can still bypass the shared write queue and hit
SQLITE_BUSY/database is lockedunder concurrent load.By allowing a
DbContextoverride to passbase.SaveChangesAsyncas the actual save delegate, applications can centralize the serialization rule once:After that, existing application code can continue calling normal EF Core APIs:
and still receive the package’s serialized-write behavior.
This is especially useful for applications migrating from normal EF Core SQLite usage to this package, because they can preserve existing
SaveChangesAsynccall sites while enforcing serialized writes consistently.Backward compatibility
This is additive and keeps the existing public API intact.
The existing overload remains:
It now delegates to the new overload using
context.SaveChangesAsync.Existing consumers should not need to change anything.
Test coverage
This PR adds a regression test using a
DbContextsubclass that overridesSaveChangesAsyncand calls the new delegate overload withbase.SaveChangesAsync.The test verifies that:
Validation
Ran:
dotnet test EntityFrameworkCore.Sqlite.Concurrency.sln --no-restore --verbosity minimalResult:
Testing
dotnet test EFCore.Sqlite.Concurrency.Test/)Checklist
CHANGELOG.mdupdated under[Unreleased]Cache=Sharedintroduced in any connection stringpackages.lock.jsonupdated if dependencies changed (dotnet restore)Breaking Changes
"None"
Summary by CodeRabbit
Improvements
Tests