@@ -156,6 +156,11 @@ private static IType GetParameterType(
156
156
return candidateType ;
157
157
}
158
158
159
+ if ( visitor . NotGuessableConstants . Contains ( constantExpression ) )
160
+ {
161
+ return null ;
162
+ }
163
+
159
164
// No related MemberExpressions was found, guess the type by value or its type when null.
160
165
// When a numeric parameter is compared to different columns with different types (e.g. Where(o => o.Single >= singleParam || o.Double <= singleParam))
161
166
// do not change the parameter type, but instead cast the parameter when comparing with different column types.
@@ -166,10 +171,13 @@ private static IType GetParameterType(
166
171
167
172
private class ConstantTypeLocatorVisitor : RelinqExpressionVisitor
168
173
{
174
+ private bool _hqlGenerator ;
169
175
private readonly bool _removeMappedAsCalls ;
170
176
private readonly System . Type _targetType ;
171
177
private readonly IDictionary < ConstantExpression , NamedParameter > _parameters ;
172
178
private readonly ISessionFactoryImplementor _sessionFactory ;
179
+ private readonly ILinqToHqlGeneratorsRegistry _functionRegistry ;
180
+ public readonly HashSet < ConstantExpression > NotGuessableConstants = new HashSet < ConstantExpression > ( ) ;
173
181
public readonly Dictionary < ConstantExpression , IType > ConstantExpressions =
174
182
new Dictionary < ConstantExpression , IType > ( ) ;
175
183
public readonly Dictionary < NamedParameter , HashSet < ConstantExpression > > ParameterConstants =
@@ -187,6 +195,7 @@ public ConstantTypeLocatorVisitor(
187
195
_targetType = targetType ;
188
196
_sessionFactory = sessionFactory ;
189
197
_parameters = parameters ;
198
+ _functionRegistry = sessionFactory . Settings . LinqToHqlGeneratorsRegistry ;
190
199
}
191
200
192
201
protected override Expression VisitBinary ( BinaryExpression node )
@@ -257,6 +266,16 @@ protected override Expression VisitMethodCall(MethodCallExpression node)
257
266
return node ;
258
267
}
259
268
269
+ // For hql method generators we do not want to guess the parameter type here, let hql logic figure it out.
270
+ if ( _functionRegistry . TryGetGenerator ( node . Method , out _ ) )
271
+ {
272
+ var origHqlGenerator = _hqlGenerator ;
273
+ _hqlGenerator = true ;
274
+ var expression = base . VisitMethodCall ( node ) ;
275
+ _hqlGenerator = origHqlGenerator ;
276
+ return expression ;
277
+ }
278
+
260
279
return base . VisitMethodCall ( node ) ;
261
280
}
262
281
@@ -267,6 +286,11 @@ protected override Expression VisitConstant(ConstantExpression node)
267
286
return node ;
268
287
}
269
288
289
+ if ( _hqlGenerator )
290
+ {
291
+ NotGuessableConstants . Add ( node ) ;
292
+ }
293
+
270
294
RelatedExpressions . Add ( node , new HashSet < Expression > ( ) ) ;
271
295
ConstantExpressions . Add ( node , null ) ;
272
296
if ( ! ParameterConstants . TryGetValue ( param , out var set ) )
0 commit comments