@@ -292,17 +292,14 @@ public bool CanAddFetchedCollectionToCache
292
292
{
293
293
get
294
294
{
295
- foreach ( var collectionFetch in CollectionFetches )
295
+ foreach ( FromElement fromElement in CollectionFetches )
296
296
{
297
- var fromElement = collectionFetch as FromElement ;
298
- var hasCache =
299
- fromElement ? . QueryableCollection != null &&
300
- fromElement . QueryableCollection . HasCache ;
297
+ var hasCache = fromElement . QueryableCollection . HasCache ;
301
298
302
299
if ( ! hasCache )
303
300
continue ;
304
301
305
- if ( ContainsRestrictionOnTable ( fromElement . TableAlias ) )
302
+ if ( ContainsRestrictionOnTable ( fromElement ) )
306
303
return false ;
307
304
}
308
305
@@ -452,34 +449,12 @@ private void ErrorIfDML()
452
449
}
453
450
}
454
451
455
- private bool ContainsRestrictionOnTable ( string tableAlias )
452
+ private bool ContainsRestrictionOnTable ( FromElement fromElement )
456
453
{
457
454
var whereClause = ( ( QueryNode ) _sqlAst ) . WhereClause ;
458
- if ( whereClause == null )
459
- return false ;
460
-
461
- var tableAliasWithDot = tableAlias + "." ;
462
- var stack = new Stack < IASTNode > ( ) ;
463
- for ( var i = 0 ; i < whereClause . ChildCount ; i ++ )
464
- {
465
- stack . Push ( whereClause . GetChild ( i ) ) ;
466
- while ( stack . Count != 0 )
467
- {
468
- var child = stack . Pop ( ) ;
469
- if ( child . ChildCount > 0 )
470
- {
471
- //We're iterating from count to 0 because it is more common to put restricting column as a left operand.
472
- //e.g WHERE fetchedCollectionAlias.Column = 1. Now we put on stack first '1' and then 'fetchedCollectionAlias.Column'
473
- //so 'fetchedCollectionAlias.Column' will be on top.
474
- for ( var j = child . ChildCount - 1 ; j >= 0 ; j -- )
475
- stack . Push ( child . GetChild ( j ) ) ;
476
- }
477
- else if ( child . Text . StartsWith ( tableAliasWithDot , StringComparison . Ordinal ) )
478
- return true ;
479
- }
480
- }
481
-
482
- return false ;
455
+ //Iterate over all nodes of type FromReferenceNode (but don't go inside FromReferenceNode with defined FromElement)
456
+ return ASTUtil . IterateChildrenOfType < FromReferenceNode > ( whereClause , skipSearchInChildrenWhen : node => node . FromElement != null )
457
+ . Any ( rn => rn . FromElement == fromElement ) ;
483
458
}
484
459
485
460
private IList < IASTNode > CollectionFetches
0 commit comments