@@ -32,28 +32,26 @@ internal sealed class NhPartialEvaluatingExpressionVisitor : RelinqExpressionVis
32
32
/// </summary>
33
33
public static Expression EvaluateIndependentSubtrees (
34
34
Expression expressionTree ,
35
- IEvaluatableExpressionFilter evaluatableExpressionFilter ,
36
- IDictionary < ConstantExpression , QueryVariable > queryVariables )
35
+ PreTransformationParameters preTransformationParameters )
37
36
{
38
- var partialEvaluationInfo = EvaluatableTreeFindingExpressionVisitor . Analyze ( expressionTree , evaluatableExpressionFilter ) ;
39
- var visitor = new NhPartialEvaluatingExpressionVisitor ( partialEvaluationInfo , evaluatableExpressionFilter , queryVariables ) ;
37
+ var partialEvaluationInfo = EvaluatableTreeFindingExpressionVisitor . Analyze (
38
+ expressionTree ,
39
+ preTransformationParameters . EvaluatableExpressionFilter ) ;
40
+ var visitor = new NhPartialEvaluatingExpressionVisitor ( partialEvaluationInfo , preTransformationParameters ) ;
40
41
41
42
return visitor . Visit ( expressionTree ) ;
42
43
}
43
44
44
45
// _partialEvaluationInfo contains a list of the expressions that are safe to be evaluated.
45
46
private readonly PartialEvaluationInfo _partialEvaluationInfo ;
46
- private readonly IEvaluatableExpressionFilter _evaluatableExpressionFilter ;
47
- private readonly IDictionary < ConstantExpression , QueryVariable > _queryVariables ;
47
+ private readonly PreTransformationParameters _preTransformationParameters ;
48
48
49
49
private NhPartialEvaluatingExpressionVisitor (
50
50
PartialEvaluationInfo partialEvaluationInfo ,
51
- IEvaluatableExpressionFilter evaluatableExpressionFilter ,
52
- IDictionary < ConstantExpression , QueryVariable > queryVariables )
51
+ PreTransformationParameters preTransformationParameters )
53
52
{
54
53
_partialEvaluationInfo = partialEvaluationInfo ;
55
- _evaluatableExpressionFilter = evaluatableExpressionFilter ;
56
- _queryVariables = queryVariables ;
54
+ _preTransformationParameters = preTransformationParameters ;
57
55
}
58
56
59
57
public override Expression Visit ( Expression expression )
@@ -81,7 +79,7 @@ public override Expression Visit(Expression expression)
81
79
82
80
if ( evaluatedExpression != expression )
83
81
{
84
- evaluatedExpression = EvaluateIndependentSubtrees ( evaluatedExpression , _evaluatableExpressionFilter , _queryVariables ) ;
82
+ evaluatedExpression = EvaluateIndependentSubtrees ( evaluatedExpression , _preTransformationParameters ) ;
85
83
}
86
84
87
85
// When having multiple level closure, we have to evaluate each closure independently
@@ -90,13 +88,15 @@ public override Expression Visit(Expression expression)
90
88
evaluatedExpression = VisitConstant ( constantExpression ) ;
91
89
}
92
90
93
- // Variables in expressions are never a constant, they are encapsulated as fields of a compiler generated class
91
+ // Variables in expressions are never a constant, they are encapsulated as fields of a compiler generated class.
92
+ // Skip detecting variables for DML queries as HQL does not support reusing parameters for them.
94
93
if ( expression . NodeType != ExpressionType . Constant &&
94
+ _preTransformationParameters . QueryMode == QueryMode . Select &&
95
95
evaluatedExpression is ConstantExpression variableConstant &&
96
- ! _queryVariables . ContainsKey ( variableConstant ) &&
96
+ ! _preTransformationParameters . QueryVariables . ContainsKey ( variableConstant ) &&
97
97
IsVariable ( expression , out var path , out var closureContext ) )
98
98
{
99
- _queryVariables . Add ( variableConstant , new QueryVariable ( path , closureContext ) ) ;
99
+ _preTransformationParameters . QueryVariables . Add ( variableConstant , new QueryVariable ( path , closureContext ) ) ;
100
100
}
101
101
102
102
return evaluatedExpression ;
@@ -106,7 +106,7 @@ protected override Expression VisitConstant(ConstantExpression expression)
106
106
{
107
107
if ( expression . Value is Expression value )
108
108
{
109
- return EvaluateIndependentSubtrees ( value , _evaluatableExpressionFilter , _queryVariables ) ;
109
+ return EvaluateIndependentSubtrees ( value , _preTransformationParameters ) ;
110
110
}
111
111
112
112
return base . VisitConstant ( expression ) ;
0 commit comments