Skip to content

Commit 6a794f5

Browse files
committed
Fix Math/MathF translation and SGN function handling
Update JetMathTranslator to distinguish between Math and MathF methods, using correct runtime methods and constant types for square root translations. Also, fix SQL function name check from "SIGN" to "SGN" for accurate SQL generation.
1 parent 8dc0f95 commit 6a794f5

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetMathTranslator.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public class JetMathTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMe
115115
nullable: true,
116116
argumentsPropagateNullability: newArguments.Select(_ => true).ToArray(),
117117
method.ReturnType,
118-
sqlFunctionName == "SIGN" ? null : typeMapping);
118+
sqlFunctionName == "SGN" ? null : typeMapping);
119119
}
120120

121121
if (_supportedMethodTranslationsIndirect.Contains(method))
@@ -132,7 +132,9 @@ public class JetMathTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMe
132132
_sqlExpressionFactory.Negate(arguments[0]),
133133
Translate(
134134
null,
135-
typeof(Math).GetMethod(nameof(Math.Sqrt))!,
135+
method.DeclaringType == typeof(MathF)
136+
? typeof(MathF).GetRuntimeMethod(nameof(MathF.Sqrt), [typeof(float)])!
137+
: typeof(Math).GetRuntimeMethod(nameof(Math.Sqrt), [typeof(double)])!,
136138
[
137139
_sqlExpressionFactory.Add(
138140
_sqlExpressionFactory.Negate(
@@ -141,7 +143,7 @@ public class JetMathTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMe
141143
arguments[0]
142144
)
143145
),
144-
_sqlExpressionFactory.Constant(1d)
146+
_sqlExpressionFactory.Constant(method.DeclaringType == typeof(MathF) ? 1f : 1d)
145147
)
146148
],
147149
logger
@@ -160,7 +162,9 @@ public class JetMathTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMe
160162
arguments[0],
161163
Translate(
162164
null,
163-
typeof(Math).GetMethod(nameof(Math.Sqrt)) !,
165+
method.DeclaringType == typeof(MathF)
166+
? typeof(MathF).GetRuntimeMethod(nameof(MathF.Sqrt), [typeof(float)])!
167+
: typeof(Math).GetRuntimeMethod(nameof(Math.Sqrt), [typeof(double)])!,
164168
[
165169
_sqlExpressionFactory.Add(
166170
_sqlExpressionFactory.Negate(
@@ -169,7 +173,7 @@ public class JetMathTranslator(ISqlExpressionFactory sqlExpressionFactory) : IMe
169173
arguments[0]
170174
)
171175
),
172-
_sqlExpressionFactory.Constant(1d)
176+
_sqlExpressionFactory.Constant(method.DeclaringType == typeof(MathF) ? 1f : 1d)
173177
)
174178
],
175179
logger

0 commit comments

Comments
 (0)