Skip to content

Commit d20e8c4

Browse files
Support inner transaction scope case
1 parent f2dda03 commit d20e8c4

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

src/NHibernate.Test/Async/NHSpecificTest/GH2750/FixtureByCode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public async Task ShouldWorkWithInnerSystemTransactionAsync()
9898
{
9999
await (session.InsertAsync(entity));
100100
}
101+
await (session.FlushBatcherAsync());
101102

102103
transaction.Complete();
103104
}

src/NHibernate.Test/NHSpecificTest/GH2750/FixtureByCode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public void ShouldWorkWithInnerSystemTransaction()
8686
{
8787
session.Insert(entity);
8888
}
89+
session.FlushBatcher();
8990

9091
transaction.Complete();
9192
}

src/NHibernate/Async/IStatelessSession.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,28 @@ public static partial class StatelessSessionExtensions
6161
cancellationToken.ThrowIfCancellationRequested();
6262
return (T) await (session.GetAsync(entityName, id, cancellationToken)).ConfigureAwait(false);
6363
}
64+
65+
/// <summary>
66+
/// Flush the batcher. When batching is enabled, a stateless session is no more fully stateless. It may retain
67+
/// in its batcher some state waiting to be flushed to the database.
68+
/// </summary>
69+
/// <param name="session">The session.</param>
70+
/// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
71+
public static Task FlushBatcherAsync(this IStatelessSession session, CancellationToken cancellationToken = default(CancellationToken))
72+
{
73+
if (cancellationToken.IsCancellationRequested)
74+
{
75+
return Task.FromCanceled<object>(cancellationToken);
76+
}
77+
try
78+
{
79+
return session.GetSessionImplementation().FlushAsync(cancellationToken);
80+
}
81+
catch (Exception ex)
82+
{
83+
return Task.FromException<object>(ex);
84+
}
85+
}
6486
}
6587

6688
public partial interface IStatelessSession : IDisposable

src/NHibernate/IStatelessSession.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ public static T Get<T>(this IStatelessSession session, string entityName, object
6464
{
6565
return (T) session.Get(entityName, id);
6666
}
67+
68+
/// <summary>
69+
/// Flush the batcher. When batching is enabled, a stateless session is no more fully stateless. It may retain
70+
/// in its batcher some state waiting to be flushed to the database.
71+
/// </summary>
72+
/// <param name="session">The session.</param>
73+
public static void FlushBatcher(this IStatelessSession session)
74+
{
75+
session.GetSessionImplementation().Flush();
76+
}
6777
}
6878

6979
/// <summary>

0 commit comments

Comments
 (0)