Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmos: Add translator for ToLower method which map to LOWER built-in function #24203

Merged
merged 3 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/EFCore.Cosmos/Query/Internal/StringMethodTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ private static readonly MethodInfo _startsWithMethodInfo
private static readonly MethodInfo _endsWithMethodInfo
= typeof(string).GetRequiredRuntimeMethod(nameof(string.EndsWith), new[] { typeof(string) });

private static readonly MethodInfo _toLowerMethodInfo
= typeof(string).GetRequiredRuntimeMethod(nameof(string.ToLower), Array.Empty<Type>());

private static readonly MethodInfo _firstOrDefaultMethodInfoWithoutArgs
= typeof(Enumerable).GetRuntimeMethods().Single(
m => m.Name == nameof(Enumerable.FirstOrDefault)
Expand Down Expand Up @@ -97,6 +100,11 @@ public StringMethodTranslator([NotNull] ISqlExpressionFactory sqlExpressionFacto
{
return TranslateSystemFunction("ENDSWITH", instance, arguments[0], typeof(bool));
}

if (_toLowerMethodInfo.Equals(method))
{
return TranslateSystemFunction("LOWER", instance, method.ReturnType);
}
}

if (_firstOrDefaultMethodInfoWithoutArgs.Equals(method))
Expand Down Expand Up @@ -141,5 +149,8 @@ public StringMethodTranslator([NotNull] ISqlExpressionFactory sqlExpressionFacto

private SqlExpression TranslateSystemFunction(string function, SqlExpression instance, SqlExpression pattern, Type returnType)
=> _sqlExpressionFactory.Function(function, new[] { instance, pattern }, returnType);

private SqlExpression TranslateSystemFunction(string function, SqlExpression instance, Type returnType)
Marusyk marked this conversation as resolved.
Show resolved Hide resolved
=> _sqlExpressionFactory.Function(function, new[] { instance }, returnType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -617,15 +617,14 @@ FROM root c
WHERE (c[""Discriminator""] = ""Customer"")");
}

[ConditionalTheory(Skip = "Issue #17246")]
public override async Task Where_string_to_lower(bool async)
{
await base.Where_string_to_lower(async);

AssertSql(
@"SELECT c
FROM root c
WHERE (c[""Discriminator""] = ""Customer"")");
WHERE ((c[""Discriminator""] = ""Customer"") AND (LOWER(c[""CustomerID""]) = ""alfki""))");
}

[ConditionalTheory(Skip = "Issue #17246")]
Expand Down