13
13
using Remotion . Linq . Clauses . Expressions ;
14
14
using Remotion . Linq . Clauses . ResultOperators ;
15
15
using Remotion . Linq . Parsing ;
16
+ using TypeExtensions = NHibernate . Util . TypeExtensions ;
16
17
17
18
namespace NHibernate . Linq . Visitors
18
19
{
@@ -50,25 +51,6 @@ public static class ParameterTypeLocator
50
51
} ;
51
52
52
53
53
- private static readonly HashSet < System . Type > IntegralNumericTypes = new HashSet < System . Type >
54
- {
55
- typeof ( sbyte ) ,
56
- typeof ( short ) ,
57
- typeof ( int ) ,
58
- typeof ( long ) ,
59
- typeof ( byte ) ,
60
- typeof ( ushort ) ,
61
- typeof ( uint ) ,
62
- typeof ( ulong )
63
- } ;
64
-
65
- private static readonly HashSet < System . Type > FloatingPointNumericTypes = new HashSet < System . Type >
66
- {
67
- typeof ( decimal ) ,
68
- typeof ( float ) ,
69
- typeof ( double )
70
- } ;
71
-
72
54
/// <summary>
73
55
/// Set query parameter types based on the given query model.
74
56
/// </summary>
@@ -150,6 +132,29 @@ private static IType GetCandidateType(
150
132
return candidateType ;
151
133
}
152
134
135
+ private static IType GetCandidateType (
136
+ ISessionFactoryImplementor sessionFactory ,
137
+ HashSet < ConstantExpression > constantExpressions ,
138
+ ConstantTypeLocatorVisitor visitor ,
139
+ System . Type constantType )
140
+ {
141
+ var candidateType = GetCandidateType ( sessionFactory , constantExpressions , visitor ) ;
142
+
143
+ if ( candidateType == null )
144
+ {
145
+ return null ;
146
+ }
147
+
148
+ // When comparing an integral column with a real parameter, the parameter type must remain real type
149
+ // and the column needs to be casted in order to prevent invalid results (e.g. Where(o => o.Integer >= 2.2d)).
150
+ if ( constantType . IsRealNumberType ( ) && candidateType . ReturnedClass . IsIntegralNumberType ( ) )
151
+ {
152
+ return null ;
153
+ }
154
+
155
+ return candidateType ;
156
+ }
157
+
153
158
private static IType GetParameterType (
154
159
ISessionFactoryImplementor sessionFactory ,
155
160
HashSet < ConstantExpression > constantExpressions ,
@@ -160,11 +165,8 @@ private static IType GetParameterType(
160
165
// All constant expressions have the same type/value
161
166
var constantExpression = constantExpressions . First ( ) ;
162
167
var constantType = constantExpression . Type . UnwrapIfNullable ( ) ;
163
- var candidateType = GetCandidateType ( sessionFactory , constantExpressions , visitor ) ;
164
- if ( candidateType != null &&
165
- // When comparing an integral column with a floating-point parameter, the parameter type must remain floating-point type
166
- // and the column needs to be casted in order to prevent invalid results (e.g. Where(o => o.Integer >= 2.2d)).
167
- ! ( FloatingPointNumericTypes . Contains ( constantType ) && IntegralNumericTypes . Contains ( candidateType . ReturnedClass ) ) )
168
+ var candidateType = GetCandidateType ( sessionFactory , constantExpressions , visitor , constantType ) ;
169
+ if ( candidateType != null )
168
170
{
169
171
return candidateType ;
170
172
}
0 commit comments