|
6 | 6 | using System.Linq.Expressions;
|
7 | 7 | using System.Runtime.Serialization;
|
8 | 8 | using System.Security;
|
| 9 | +using System.Threading; |
9 | 10 | using NHibernate.AdoNet;
|
10 | 11 | using NHibernate.Collection;
|
11 | 12 | using NHibernate.Criterion;
|
@@ -73,7 +74,7 @@ public sealed class SessionImpl : AbstractSessionImpl, IEventSource, ISerializab
|
73 | 74 | private readonly StatefulPersistenceContext persistenceContext;
|
74 | 75 |
|
75 | 76 | [NonSerialized]
|
76 |
| - private readonly ISession rootSession; |
| 77 | + private readonly SessionImpl rootSession; |
77 | 78 |
|
78 | 79 | [NonSerialized]
|
79 | 80 | ISession _childSession;
|
@@ -1681,6 +1682,9 @@ private void Dispose(bool isDisposing)
|
1681 | 1682 | // free unmanaged resources here
|
1682 | 1683 |
|
1683 | 1684 | IsAlreadyDisposed = true;
|
| 1685 | + |
| 1686 | + rootSession?.RemoveChildSession(this); |
| 1687 | + |
1684 | 1688 | // nothing for Finalizer to do - so tell the GC to ignore it
|
1685 | 1689 | GC.SuppressFinalize(this);
|
1686 | 1690 | }
|
@@ -2221,10 +2225,8 @@ public ISession GetChildSession()
|
2221 | 2225 |
|
2222 | 2226 | CheckAndUpdateSessionStatus();
|
2223 | 2227 |
|
2224 |
| - var childImpl = _childSession as SessionImpl; |
2225 |
| - |
2226 | 2228 | // if child session never existed or has already been disposed, create new
|
2227 |
| - if (childImpl == null || childImpl.IsAlreadyDisposed) |
| 2229 | + if (_childSession == null) |
2228 | 2230 | {
|
2229 | 2231 | log.Debug("Creating child session.");
|
2230 | 2232 | _childSession = new SessionImpl(this);
|
@@ -2607,5 +2609,10 @@ public override IEntityPersister GetEntityPersister(string entityName, object ob
|
2607 | 2609 | }
|
2608 | 2610 | }
|
2609 | 2611 | }
|
| 2612 | + |
| 2613 | + void RemoveChildSession(ISession session) |
| 2614 | + { |
| 2615 | + Interlocked.CompareExchange(ref _childSession, null, session); |
| 2616 | + } |
2610 | 2617 | }
|
2611 | 2618 | }
|
0 commit comments