-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Add support for System.Transactions #9561
Conversation
{ | ||
using (var transaction = TestStore.BeginTransaction()) | ||
{ | ||
using (var context = CreateContextWithConnectionString()) | ||
{ | ||
context.Database.AutoTransactionsEnabled = autoTransaction; |
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.
Why did this change?
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.
Redundant test. AutoTransactionsEnabled only affects SaveChanges. This test doesn't call SaveChanges.
@@ -104,6 +104,53 @@ protected RelationalConnection([NotNull] RelationalConnectionDependencies depend | |||
public virtual IDbContextTransaction CurrentTransaction { get; [param: CanBeNull] protected set; } | |||
|
|||
/// <summary> | |||
/// The currently enlisted transaction. |
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.
I think we need more here to document what flavor of .NET transaction this "Transaction" type is. @divega?
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.
System.Transactions.Transaction?
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.
@divega I was thinking of some more words than this to help people decide which to use...
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.
Ok. I misunderstood. Stepping back I think these API additions can be very confusing. Not sure additional words in the member documentation are going to help.
I am thinking we should brainstorm something we can use in the API names as well to differentiate from the normal scenarios we already support. Right now "external transaction" comes to mind.
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.
Another approach suggested by @anpete would be to make these extension methods in the System.Transactions namespace, so people have to add a using statement to light the API up.
// the connection. This will enlist the newly opened connection to the second transaction but will also close the reader being used | ||
// by the first active query. As a result when trying to continue reading results from the first query the user will get an exception | ||
// saying that calling "Read" on a closed data reader is not a valid operation. | ||
AmbientTransaction = current; |
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.
I may be missing something here, but is this better than just throwing? In other words, what's the valid scenario where we need to do this?
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.
This is EF6 behavior. If the query reader enlisted in the first transaction is never read from after this the second operation will still work. We can choose to throw instead.
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.
Not sure, would like to discuss with @divega
7e0f505
to
0d00876
Compare
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.
Approving with the changes to close/open discussed in person.
b6d4663
to
810aa01
Compare
@divega, @ajcvickers I've updated with extension methods and connection keep-alive. Can you review again? I found a scenario broken by the keep-alive: using (new TransactionScope())
{
// query
using (new TransactionScope(TransactionScopeOption.Suppress))
{
// query
}
// SaveChanges
} Now the middle query would still be executed in the transaction. If we tried to unenlist it would throw. |
Is this a scenario in which you would really need more than one connection? Then it is kind of nice if it throws... |
d897a89
to
6bf389d
Compare
Signing off on the latest changes. |
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.
Upgrading to providers-beware since there is new API here ( |
6bf389d
to
792ee4d
Compare
No milestone set so I wonder: When could we expect this on NuGet? |
@bruno-garcia This is just a pull request, the corresponding issue is #5595 and it's in the 2.1.0 milestone |
My bad. I got to the issue after asking here. |
So, I guess this is still not supported? I'm currently using 2.02 and still getting the same issue. |
@codematrix This feature is in 2.1.0-preview1 |
FYI, am adding support for this in Npgsql and wanted to share some info. Some of the tests purposefully generated an error and then continue with the TransactionScope ( Ideally these tests wouldn't depend on continuing after a failure. But it's no big deal - mostly wanted you to know that you cannot rely on a transaction being recoverable after an error across databases. |
@AndriySvyryd Should we file a test issue for this? |
Filed #12001 |
The tests currently only run for SQL Server on net461
Fixes #5595