Skip to content

Commit 13c5235

Browse files
committed
NestedRelationalTransactionManager implements ITransactionEnlistmentManager
1 parent 3eb8c8e commit 13c5235

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/Thinktecture.EntityFrameworkCore.Relational/EntityFrameworkCore/Storage/NestedRelationalTransactionManager.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
using System.Data;
21
using System.Data.Common;
2+
using System.Transactions;
33
using Microsoft.EntityFrameworkCore.Diagnostics;
44
using Microsoft.EntityFrameworkCore.Storage;
55
using Microsoft.Extensions.Logging;
6+
using IsolationLevel = System.Data.IsolationLevel;
67

78
namespace Thinktecture.EntityFrameworkCore.Storage;
89

910
/// <summary>
1011
/// Transaction manager with nested transaction support.
1112
/// </summary>
12-
public class NestedRelationalTransactionManager : IRelationalTransactionManager
13+
public class NestedRelationalTransactionManager : IRelationalTransactionManager, ITransactionEnlistmentManager
1314
{
1415
private readonly IDiagnosticsLogger<RelationalDbLoggerCategory.NestedTransaction> _logger;
15-
private readonly IRelationalTransactionManager _innerManager;
16+
private readonly IRelationalConnection _innerManager;
17+
private readonly ITransactionEnlistmentManager? _enlistmentManager;
1618
private readonly Stack<NestedDbContextTransaction> _transactions;
1719

1820
/// <inheritdoc />
1921
public IDbContextTransaction? CurrentTransaction => CurrentNestedTransaction;
2022

2123
private NestedDbContextTransaction? CurrentNestedTransaction => _transactions.FirstOrDefault();
2224

25+
/// <inheritdoc />
26+
public Transaction? EnlistedTransaction => (_enlistmentManager ?? throw new NotSupportedException("The current provider doesn't support System.Transaction.")).EnlistedTransaction;
27+
2328
/// <summary>
2429
/// Initializes new instance of <see cref="NestedRelationalTransactionManager"/>.
2530
/// </summary>
@@ -31,9 +36,17 @@ public NestedRelationalTransactionManager(
3136
{
3237
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
3338
_innerManager = connection ?? throw new ArgumentNullException(nameof(connection));
39+
_enlistmentManager = connection as ITransactionEnlistmentManager;
3440
_transactions = new Stack<NestedDbContextTransaction>();
3541
}
3642

43+
/// <inheritdoc />
44+
public void EnlistTransaction(Transaction? transaction)
45+
{
46+
(_enlistmentManager ?? throw new NotSupportedException("The current provider doesn't support System.Transaction."))
47+
.EnlistTransaction(transaction);
48+
}
49+
3750
/// <inheritdoc />
3851
public IDbContextTransaction? UseTransaction(
3952
DbTransaction? transaction)

0 commit comments

Comments
 (0)