Skip to content

Commit b89c16b

Browse files
hazzikmaca88
authored andcommitted
Move number type checks to TypeExtensions and extract additional method to make code more readable
1 parent 98de5ae commit b89c16b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/NHibernate/Linq/Visitors/ParameterTypeLocator.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,29 @@ private static IType GetCandidateType(
141141
return candidateType;
142142
}
143143

144+
private static IType GetCandidateType(
145+
ISessionFactoryImplementor sessionFactory,
146+
HashSet<ConstantExpression> constantExpressions,
147+
ConstantTypeLocatorVisitor visitor,
148+
System.Type constantType)
149+
{
150+
var candidateType = GetCandidateType(sessionFactory, constantExpressions, visitor);
151+
152+
if (candidateType == null)
153+
{
154+
return null;
155+
}
156+
157+
// When comparing an integral column with a real parameter, the parameter type must remain real type
158+
// and the column needs to be casted in order to prevent invalid results (e.g. Where(o => o.Integer >= 2.2d)).
159+
if (constantType.IsRealNumberType() && candidateType.ReturnedClass.IsIntegralNumberType())
160+
{
161+
return null;
162+
}
163+
164+
return candidateType;
165+
}
166+
144167
private static IType GetParameterType(
145168
ISessionFactoryImplementor sessionFactory,
146169
HashSet<ConstantExpression> constantExpressions,

0 commit comments

Comments
 (0)