-
Notifications
You must be signed in to change notification settings - Fork 2k
EfCore.InMemory.Transactions is added #5254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ErikEJ
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
I honestly was not aware we were throwing for transactions with a non-default isolation level. I don't think we should - regardless of the isolation level, when using the InMemory provider the transaction is simply ignored, so I think it makes just as much sense to do that when an isolation level is specified or not. Or am I missing/misunderstanding something? |
|
Hi @roji, thanks for the feedback!
So transactions are not "simply ignored" by default - they throw. You need to explicitly configure: .ConfigureWarnings(b => b.Ignore(InMemoryEventId.TransactionIgnoredWarning))to make However, even WITH that configuration, calling So there are actually two separate issues:
My package addresses both cases with a unified approach, allowing the same transaction code to work in production and tests without modifications. |
|
@roji, based on your feedback I've submitted a PR to fix this in EF Core itself: In the meantime, my package (EfCore.InMemory.Transactions) can help developers who need this fix today or are using older EF Core versions (8, 9, 10) that won't receive this update. |
This PR adds https://github.com/ShadyNagy/EfCore.InMemory.Transactions to the EF Core extensions list.
What it does
Provides seamless transaction support for EF Core's InMemory provider by offering safe extension methods (BeginTransactionSafeAsync) and a NoOpDbContextTransaction class. This eliminates the common "transactions with isolation level are not supported" error when running integration tests with InMemory database.
Why it's useful
Developers using transactions with isolation levels in production code face exceptions when testing with InMemory provider. This package allows the same code to work in both production and test environments without conditional logic scattered throughout the codebase.
The problem
The solution
Package info
Hi @ErikEJ @AndriySvyryd
I appreciate your support and review.
Thanks!