@@ -271,9 +271,7 @@ bool CheckCacheAndProcessResult()
271
271
? collectionKeys . Count - Math . Min ( batchSize , collectionKeys . Count )
272
272
: 0 ;
273
273
var toIndex = collectionKeys . Count - 1 ;
274
- // In case the collection having triggered the load was not registered for batching, load
275
- // most recently registered collections.
276
- var indexes = GetSortedKeyIndexes ( collectionKeys , keyIndex ?? - 1 , fromIndex , toIndex ) ;
274
+ var indexes = GetSortedKeyIndexes ( collectionKeys , keyIndex , fromIndex , toIndex ) ;
277
275
if ( batchableCache == null )
278
276
{
279
277
for ( var j = 0 ; j < collectionKeys . Count ; j ++ )
@@ -457,10 +455,7 @@ bool CheckCacheAndProcessResult()
457
455
? entityKeys . Count - Math . Min ( batchSize , entityKeys . Count )
458
456
: 0 ;
459
457
var toIndex = entityKeys . Count - 1 ;
460
- // In case of an ISession.Get on an entity not already loaded as an uninitialized proxy,
461
- // it will not be found in entities awaiting a load, and idIndex will be null. Providing
462
- // -1 then allows to take the entities most recently loaded as uninitialized proxies.
463
- var indexes = GetSortedKeyIndexes ( entityKeys , idIndex ?? - 1 , fromIndex , toIndex ) ;
458
+ var indexes = GetSortedKeyIndexes ( entityKeys , idIndex , fromIndex , toIndex ) ;
464
459
if ( batchableCache == null )
465
460
{
466
461
for ( var j = 0 ; j < entityKeys . Count ; j ++ )
@@ -626,13 +621,15 @@ private bool[] AreCached(List<KeyValuePair<KeyValuePair<CollectionEntry, IPersis
626
621
/// <param name="fromIndex">The index where the sorting will begin.</param>
627
622
/// <param name="toIndex">The index where the sorting will end.</param>
628
623
/// <returns>An array of sorted key indexes.</returns>
629
- private static int [ ] GetSortedKeyIndexes < T > ( List < KeyValuePair < T , int > > keys , int keyIndex , int fromIndex , int toIndex )
624
+ private static int [ ] GetSortedKeyIndexes < T > ( List < KeyValuePair < T , int > > keys , int ? keyIndex , int fromIndex , int toIndex )
630
625
{
631
626
var result = new int [ Math . Abs ( toIndex - fromIndex ) + 1 ] ;
632
627
var lowerIndexes = new List < int > ( ) ;
633
628
var i = 0 ;
634
629
for ( var j = fromIndex ; j <= toIndex ; j ++ )
635
630
{
631
+ // If the index was not found (null), this test will be falsy and it will take the most recently
632
+ // registered entities or collections.
636
633
if ( keys [ j ] . Value < keyIndex )
637
634
{
638
635
lowerIndexes . Add ( j ) ;
0 commit comments