@@ -651,28 +651,7 @@ private async Task InstanceAlreadyLoadedAsync(DbDataReader rs, int i, IEntityPer
651651 }
652652 }
653653
654- // #1226: If it is already loaded and can be loaded from an association with a property ref, make
655- // sure it is also cached by its unique key.
656- var ukName = OwnerAssociationTypes ? [ i ] ? . RHSUniqueKeyPropertyName ;
657- if ( ukName == null )
658- return ;
659- var index = ( ( IUniqueKeyLoadable ) persister ) . GetPropertyIndex ( ukName ) ;
660- var ukValue = persister . GetPropertyValue ( obj , index ) ;
661- // ukValue can be null for two reasons:
662- // - Entity currently loading and not yet fully hydrated. In such case, it has already been handled by
663- // InstanceNotYetLoaded on a previous row, there is nothing more to do. This case could also be
664- // detected with "session.PersistenceContext.GetEntry(obj).Status == Status.Loading", but since there
665- // is a second case, just test for ukValue null.
666- // - Entity association is unset in session but not yet persisted, autoflush disabled: ignore. We are
667- // already in an error case: querying entities changed in session without flushing them before querying.
668- // So here it gets loaded as if it were still associated, but we do not have the key anymore in session:
669- // we cannot cache it, so long for the additionnal round-trip this will cause. (Do not fallback on
670- // reading the key in rs, this is stale data in regard to the session state.)
671- if ( ukValue == null )
672- return ;
673- var type = persister . PropertyTypes [ index ] ;
674- var euk = new EntityUniqueKey ( persister . EntityName , ukName , ukValue , type , session . Factory ) ;
675- session . PersistenceContext . AddEntity ( euk , obj ) ;
654+ CacheByUniqueKey ( i , persister , obj , session ) ;
676655 }
677656
678657 /// <summary>
0 commit comments