Skip to content

Commit 20bc900

Browse files
Copilotrenemadsen
andcommitted
Add type mapping for LEAST and GREATEST functions
- LEAST and GREATEST functions now infer type mapping from first argument - Falls back to result type mapping if first argument has no mapping - Addresses type mapping assignment error for LEAST/GREATEST expressions Note: Tests still failing with "Undeclared variable: LEAST" error - investigating further Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
1 parent ac489ec commit 20bc900

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/EFCore.MySql/Query/ExpressionVisitors/Internal/MySqlSqlTranslatingExpressionVisitor.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,18 +423,30 @@ protected virtual void ResetTranslationErrorDetails()
423423
}
424424

425425
public override SqlExpression GenerateGreatest(IReadOnlyList<SqlExpression> expressions, Type resultType)
426-
=> _sqlExpressionFactory.NullableFunction(
426+
{
427+
var typeMapping = expressions.FirstOrDefault()?.TypeMapping
428+
?? _sqlExpressionFactory.FindMapping(resultType, null);
429+
430+
return _sqlExpressionFactory.NullableFunction(
427431
"GREATEST",
428432
expressions,
429433
resultType,
434+
typeMapping,
430435
true);
436+
}
431437

432438
public override SqlExpression GenerateLeast(IReadOnlyList<SqlExpression> expressions, Type resultType)
433-
=> _sqlExpressionFactory.NullableFunction(
439+
{
440+
var typeMapping = expressions.FirstOrDefault()?.TypeMapping
441+
?? _sqlExpressionFactory.FindMapping(resultType, null);
442+
443+
return _sqlExpressionFactory.NullableFunction(
434444
"LEAST",
435445
expressions,
436446
resultType,
447+
typeMapping,
437448
true);
449+
}
438450

439451
#region Copied from RelationalSqlTranslatingExpressionVisitor
440452

0 commit comments

Comments
 (0)