Skip to content

Commit 7969cf3

Browse files
committed
Move proxy check before interceptor
1 parent 986fa50 commit 7969cf3

File tree

2 files changed

+17
-31
lines changed

2 files changed

+17
-31
lines changed

src/NHibernate/Async/Engine/ForeignKeys.cs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -171,37 +171,25 @@ public static async Task<bool> IsNotTransientSlowAsync(string entityName, object
171171
/// <remarks>
172172
/// Don't hit the database to make the determination, instead return null;
173173
/// </remarks>
174-
public static Task<bool?> IsTransientFastAsync(string entityName, object entity, ISessionImplementor session, CancellationToken cancellationToken)
174+
public static async Task<bool?> IsTransientFastAsync(string entityName, object entity, ISessionImplementor session, CancellationToken cancellationToken)
175175
{
176-
if (cancellationToken.IsCancellationRequested)
176+
cancellationToken.ThrowIfCancellationRequested();
177+
if (Equals(Intercept.LazyPropertyInitializer.UnfetchedProperty, entity))
177178
{
178-
return Task.FromCanceled<bool?>(cancellationToken);
179+
// an unfetched association can only point to
180+
// an entity that already exists in the db
181+
return false;
179182
}
180-
try
181-
{
182-
if (Equals(Intercept.LazyPropertyInitializer.UnfetchedProperty, entity))
183-
{
184-
// an unfetched association can only point to
185-
// an entity that already exists in the db
186-
return Task.FromResult<bool?>(false);
187-
}
188-
189-
// let the interceptor inspect the instance to decide
190-
if (session.Interceptor.IsTransient(entity) == true)
191-
return Task.FromResult<bool?>(true);
192183

193-
if (entity is INHibernateProxy proxy && proxy.HibernateLazyInitializer.IsUninitialized)
194-
{
195-
return Task.FromResult<bool?>(false);
196-
}
197-
198-
// let the persister inspect the instance to decide
199-
return session.GetEntityPersister(entityName, entity).IsTransientAsync(entity, session, cancellationToken);
200-
}
201-
catch (System.Exception ex)
184+
if (entity is INHibernateProxy proxy && proxy.HibernateLazyInitializer.IsUninitialized)
202185
{
203-
return Task.FromException<bool?>(ex);
186+
return false;
204187
}
188+
189+
// let the interceptor inspect the instance to decide
190+
// let the persister inspect the instance to decide
191+
return session.Interceptor.IsTransient(entity) ??
192+
await (session.GetEntityPersister(entityName, entity).IsTransientAsync(entity, session, cancellationToken)).ConfigureAwait(false);
205193
}
206194

207195
/// <summary>

src/NHibernate/Engine/ForeignKeys.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,15 @@ public static bool IsNotTransientSlow(string entityName, object entity, ISession
178178
return false;
179179
}
180180

181-
// let the interceptor inspect the instance to decide
182-
if (session.Interceptor.IsTransient(entity) == true)
183-
return true;
184-
185181
if (entity is INHibernateProxy proxy && proxy.HibernateLazyInitializer.IsUninitialized)
186182
{
187183
return false;
188184
}
189185

190-
// let the persister inspect the instance to decide
191-
return session.GetEntityPersister(entityName, entity).IsTransient(entity, session);
186+
// let the interceptor inspect the instance to decide
187+
// let the persister inspect the instance to decide
188+
return session.Interceptor.IsTransient(entity) ??
189+
session.GetEntityPersister(entityName, entity).IsTransient(entity, session);
192190
}
193191

194192
/// <summary>

0 commit comments

Comments
 (0)