7
7
using NHibernate . Hql . Ast . ANTLR ;
8
8
using NHibernate . Hql . Ast . ANTLR . Tree ;
9
9
using NHibernate . Hql . Ast . ANTLR . Util ;
10
+ using NHibernate . Linq ;
10
11
using NHibernate . Type ;
11
12
using NHibernate . Util ;
12
13
@@ -27,7 +28,7 @@ protected ExpressionQueryImpl(
27
28
_isFilter = isFilter ;
28
29
}
29
30
30
- public IQueryExpression QueryExpression { get ; private set ; }
31
+ public IQueryExpression QueryExpression { get ; }
31
32
32
33
protected readonly bool _isFilter ;
33
34
@@ -81,10 +82,15 @@ protected override IQueryExpression ExpandParameters(IDictionary<string, TypedVa
81
82
return QueryExpression ;
82
83
}
83
84
84
- //TODO: Do we need to translate expression one more time here?
85
- // This is not much an issue anymore: ExpressionQueryImpl are currently created only with NhLinqExpression
86
- // which do cache their translation.
87
- var newTree = ParameterExpander . Expand ( QueryExpression . Translate ( Session . Factory , _isFilter ) , map ) ;
85
+ // Translating expression one more time here is not much an issue anymore: when using the default Linq
86
+ // provider, ExpressionQueryImpl are created only with NhLinqExpression, which do cache their translation.
87
+ var newTree = ParameterExpander . Expand (
88
+ QueryExpression is NhLinqExpression linqExpr ?
89
+ // Avoid cloning, the parameter expander does (and need to) clone too.
90
+ linqExpr . Translate ( Session . Factory , _isFilter , false ) :
91
+ // A custom Linq provider may supply something else than a NhLinqExpression, support it.
92
+ QueryExpression . Translate ( Session . Factory , _isFilter ) ,
93
+ map ) ;
88
94
var key = new StringBuilder ( QueryExpression . Key ) ;
89
95
90
96
foreach ( var pair in map )
@@ -201,7 +207,7 @@ private IASTNode Expand()
201
207
var parameters = ParameterDetector . LocateParameters ( _tree , new HashSet < string > ( _map . Keys ) ) ;
202
208
var nodeMapping = new Dictionary < IASTNode , IEnumerable < IASTNode > > ( ) ;
203
209
204
- foreach ( IASTNode param in parameters )
210
+ foreach ( var param in parameters )
205
211
{
206
212
var paramName = param . GetChild ( 0 ) ;
207
213
var aliases = _map [ paramName . Text ] ;
0 commit comments