4
4
using NHibernate . Hql . Ast . ANTLR ;
5
5
using NHibernate . Persister . Entity ;
6
6
using NHibernate . Type ;
7
+ using Remotion . Linq . Clauses . StreamedData ;
7
8
using Remotion . Linq . EagerFetching ;
8
9
9
10
namespace NHibernate . Linq . Visitors . ResultOperatorProcessors
@@ -12,20 +13,32 @@ public class ProcessFetch
12
13
{
13
14
public void Process ( FetchRequestBase resultOperator , QueryModelVisitor queryModelVisitor , IntermediateHqlTree tree )
14
15
{
15
- var lastFromNode = tree . GetLastFromChildNode ( ) ;
16
- Process ( resultOperator , queryModelVisitor , tree , lastFromNode , GetNodeAlias ( lastFromNode ) ) ;
16
+ var selector = ( ( StreamedSequenceInfo ) queryModelVisitor . PreviousEvaluationType ) . ItemExpression ;
17
+ var querySource = QuerySourceExtractor . GetQuerySource ( selector ) ;
18
+ var sourceAlias = queryModelVisitor . VisitorParameters . QuerySourceNamer . GetName ( querySource ) ;
19
+ Process ( resultOperator , queryModelVisitor , tree , GetFromNodeByAlias ( tree , sourceAlias ) , sourceAlias ) ;
17
20
}
18
21
19
- private static string GetNodeAlias ( HqlTreeNode lastFrom )
22
+ private static HqlTreeNode GetFromNodeByAlias ( IntermediateHqlTree tree , string sourceAlias )
20
23
{
21
- return lastFrom . Children . Select ( x => x . AstNode )
24
+ return tree . Root . NodesPreOrder
25
+ . First ( x => x . AstNode . Type == HqlSqlWalker . FROM ) . Children
26
+ . First ( x => GetNodeAlias ( x ) == sourceAlias ) ;
27
+ }
28
+
29
+ private static string GetNodeAlias ( HqlTreeNode fromNode )
30
+ {
31
+ return fromNode . Children
32
+ . Select ( x => x . AstNode )
22
33
. First ( x => x . Type == HqlSqlWalker . ALIAS )
23
34
. Text ;
24
35
}
25
36
37
+ // Since v5.5
38
+ [ Obsolete ( "This method is not used and will be removed in a future version." ) ]
26
39
public void Process ( FetchRequestBase resultOperator , QueryModelVisitor queryModelVisitor , IntermediateHqlTree tree , string sourceAlias )
27
40
{
28
- Process ( resultOperator , queryModelVisitor , tree , null , sourceAlias ) ;
41
+ Process ( resultOperator , queryModelVisitor , tree , GetFromNodeByAlias ( tree , sourceAlias ) , sourceAlias ) ;
29
42
}
30
43
31
44
private void Process (
@@ -72,13 +85,12 @@ private void Process(
72
85
propType = metadata . GetPropertyType ( resultOperator . RelationMember . Name ) ;
73
86
}
74
87
}
75
-
88
+
76
89
if ( propType != null && ! propType . IsAssociationType )
77
90
{
78
91
if ( currentNode == null )
79
92
{
80
- currentNode = tree . GetLastFromChildNode ( )
81
- ?? throw new InvalidOperationException ( $ "Property { resultOperator . RelationMember . Name } cannot be fetched for this type of query.") ;
93
+ throw new InvalidOperationException ( $ "Property { resultOperator . RelationMember . Name } cannot be fetched for this type of query.") ;
82
94
}
83
95
84
96
currentNode . AddChild ( tree . TreeBuilder . Fetch ( ) ) ;
@@ -89,12 +101,13 @@ private void Process(
89
101
{
90
102
if ( componentType == null )
91
103
{
92
- componentType = propType as ComponentType ;
93
- if ( componentType == null )
104
+ if ( ! propType . IsComponentType )
94
105
{
95
106
throw new InvalidOperationException (
96
107
$ "Property { innerFetch . RelationMember . Name } cannot be fetched from a non component type property { resultOperator . RelationMember . Name } .") ;
97
108
}
109
+
110
+ componentType = ( ComponentType ) propType ;
98
111
}
99
112
100
113
var subTypeIndex = componentType . GetPropertyIndex ( innerFetch . RelationMember . Name ) ;
0 commit comments