@@ -432,10 +432,11 @@ public LockMode GetCurrentLockMode(object obj)
432
432
{
433
433
throw new ArgumentNullException ( "obj" , "null object passed to GetCurrentLockMode" ) ;
434
434
}
435
- var proxy = obj as INHibernateProxy ;
436
- if ( proxy != null )
435
+
436
+ if ( obj . IsProxy ( ) )
437
437
{
438
- obj = proxy . HibernateLazyInitializer . GetImplementation ( this ) ;
438
+ var proxy = obj as INHibernateProxy ;
439
+ obj = proxy . HibernateLazyInitializer . GetImplementation ( this ) ;
439
440
if ( obj == null )
440
441
{
441
442
return LockMode . None ;
@@ -1040,10 +1041,10 @@ public override string BestGuessEntityName(object entity)
1040
1041
{
1041
1042
using ( new SessionIdLoggingContext ( SessionId ) )
1042
1043
{
1043
- INHibernateProxy proxy = entity as INHibernateProxy ;
1044
- if ( proxy != null )
1044
+ if ( entity . IsProxy ( ) )
1045
1045
{
1046
- ILazyInitializer initializer = proxy . HibernateLazyInitializer ;
1046
+ INHibernateProxy proxy = entity as INHibernateProxy ;
1047
+ ILazyInitializer initializer = proxy . HibernateLazyInitializer ;
1047
1048
1048
1049
// it is possible for this method to be called during flush processing,
1049
1050
// so make certain that we do not accidently initialize an uninitialized proxy
@@ -1292,10 +1293,12 @@ public string GetEntityName(object obj)
1292
1293
using ( new SessionIdLoggingContext ( SessionId ) )
1293
1294
{
1294
1295
CheckAndUpdateSessionStatus ( ) ;
1295
- var proxy = obj as INHibernateProxy ;
1296
- if ( proxy != null )
1296
+
1297
+ if ( obj . IsProxy ( ) )
1297
1298
{
1298
- if ( ! persistenceContext . ContainsProxy ( proxy ) )
1299
+ var proxy = obj as INHibernateProxy ;
1300
+
1301
+ if ( ! persistenceContext . ContainsProxy ( proxy ) )
1299
1302
{
1300
1303
throw new TransientObjectException ( "proxy was not associated with the session" ) ;
1301
1304
}
@@ -1517,10 +1520,12 @@ public object GetIdentifier(object obj)
1517
1520
// Actually the case for proxies will probably work even with
1518
1521
// the session closed, but do the check here anyway, so that
1519
1522
// the behavior is uniform.
1520
- var proxy = obj as INHibernateProxy ;
1521
- if ( proxy != null )
1523
+
1524
+ if ( obj . IsProxy ( ) )
1522
1525
{
1523
- ILazyInitializer li = proxy . HibernateLazyInitializer ;
1526
+ var proxy = obj as INHibernateProxy ;
1527
+
1528
+ ILazyInitializer li = proxy . HibernateLazyInitializer ;
1524
1529
if ( li . Session != this )
1525
1530
{
1526
1531
throw new TransientObjectException ( "The proxy was not associated with this session" ) ;
@@ -1547,10 +1552,11 @@ public override object GetContextEntityIdentifier(object obj)
1547
1552
{
1548
1553
using ( new SessionIdLoggingContext ( SessionId ) )
1549
1554
{
1550
- INHibernateProxy proxy = obj as INHibernateProxy ;
1551
- if ( proxy != null )
1555
+ if ( obj . IsProxy ( ) )
1552
1556
{
1553
- return proxy . HibernateLazyInitializer . Identifier ;
1557
+ INHibernateProxy proxy = obj as INHibernateProxy ;
1558
+
1559
+ return proxy . HibernateLazyInitializer . Identifier ;
1554
1560
}
1555
1561
else
1556
1562
{
@@ -1942,10 +1948,12 @@ public bool Contains(object obj)
1942
1948
using ( new SessionIdLoggingContext ( SessionId ) )
1943
1949
{
1944
1950
CheckAndUpdateSessionStatus ( ) ;
1945
- var proxy = obj as INHibernateProxy ;
1946
- if ( proxy != null )
1951
+
1952
+ if ( obj . IsProxy ( ) )
1947
1953
{
1948
- //do not use proxiesByKey, since not all
1954
+ var proxy = obj as INHibernateProxy ;
1955
+
1956
+ //do not use proxiesByKey, since not all
1949
1957
//proxies that point to this session's
1950
1958
//instances are in that collection!
1951
1959
ILazyInitializer li = proxy . HibernateLazyInitializer ;
0 commit comments