@@ -3686,35 +3686,34 @@ public virtual void AfterReassociate(object entity, ISessionImplementor session)
36863686 return true ;
36873687 }
36883688
3689- // check the version unsaved-value, if appropriate
3690- if ( IsVersioned )
3691- {
3692- object version = GetVersion ( entity , session . EntityMode ) ;
3693- // let this take precedence if defined, since it works for
3694- // assigned identifiers
3695- bool ? result = entityMetamodel . VersionProperty . UnsavedValue . IsUnsaved ( version ) ;
3696- if ( result . HasValue )
3697- {
3698- return result ;
3699- }
3700- }
3701-
3702- // check the id unsaved-value
3703- bool ? result2 = entityMetamodel . IdentifierProperty . UnsavedValue . IsUnsaved ( id ) ;
3704- if ( result2 . HasValue )
3705- {
3706- if ( IdentifierGenerator is Assigned )
3707- {
3708- // if using assigned identifier, we can only make assumptions
3709- // if the value is a known unsaved-value
3710- if ( result2 . Value )
3711- return true ;
3712- }
3713- else
3714- {
3715- return result2 ;
3716- }
3717- }
3689+ // check the id unsaved-value
3690+ // We do this first so we don't have to hydrate the version property if the id property already gives us the info we need (NH-3505).
3691+ bool ? result2 = entityMetamodel . IdentifierProperty . UnsavedValue . IsUnsaved ( id ) ;
3692+ if ( result2 . HasValue )
3693+ {
3694+ if ( IdentifierGenerator is Assigned )
3695+ {
3696+ // if using assigned identifier, we can only make assumptions
3697+ // if the value is a known unsaved-value
3698+ if ( result2 . Value )
3699+ return true ;
3700+ }
3701+ else
3702+ {
3703+ return result2 ;
3704+ }
3705+ }
3706+
3707+ // check the version unsaved-value, if appropriate
3708+ if ( IsVersioned )
3709+ {
3710+ object version = GetVersion ( entity , session . EntityMode ) ;
3711+ bool ? result = entityMetamodel . VersionProperty . UnsavedValue . IsUnsaved ( version ) ;
3712+ if ( result . HasValue )
3713+ {
3714+ return result ;
3715+ }
3716+ }
37183717
37193718 // check to see if it is in the second-level cache
37203719 if ( HasCache )
0 commit comments