diff --git a/src/EFCore.Cosmos/Query/Internal/StringMethodTranslator.cs b/src/EFCore.Cosmos/Query/Internal/StringMethodTranslator.cs index 93a845ae18e..5f0bcbcc31e 100644 --- a/src/EFCore.Cosmos/Query/Internal/StringMethodTranslator.cs +++ b/src/EFCore.Cosmos/Query/Internal/StringMethodTranslator.cs @@ -250,14 +250,17 @@ public StringMethodTranslator(ISqlExpressionFactory sqlExpressionFactory) || _stringComparisonWithComparisonTypeArgumentStatic.Equals(method)) { var comparisonTypeArgument = arguments[^1]; + if (comparisonTypeArgument is SqlConstantExpression constantComparisonTypeArgument && constantComparisonTypeArgument.Value is StringComparison comparisonTypeArgumentValue - && comparisonTypeArgumentValue == StringComparison.OrdinalIgnoreCase) + && (comparisonTypeArgumentValue == StringComparison.OrdinalIgnoreCase + || comparisonTypeArgumentValue == StringComparison.Ordinal)) { + var ignoreCase = _sqlExpressionFactory.Constant(comparisonTypeArgumentValue == StringComparison.OrdinalIgnoreCase); return _stringComparisonWithComparisonTypeArgumentInstance.Equals(method) - ? TranslateSystemFunction("STRINGEQUALS", typeof(bool), instance!, arguments[0], _sqlExpressionFactory.Constant(true)) - : TranslateSystemFunction("STRINGEQUALS", typeof(bool), arguments[0], arguments[1], _sqlExpressionFactory.Constant(true)); + ? TranslateSystemFunction("STRINGEQUALS", typeof(bool), instance!, arguments[0], ignoreCase) + : TranslateSystemFunction("STRINGEQUALS", typeof(bool), arguments[0], arguments[1], ignoreCase); } } diff --git a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs index 4527f2aaa7a..9d977803a8f 100644 --- a/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs +++ b/test/EFCore.Cosmos.FunctionalTests/Query/NorthwindFunctionsQueryCosmosTest.cs @@ -1365,6 +1365,36 @@ FROM root c WHERE ((c[""Discriminator""] = ""Customer"") AND STRINGEQUALS(c[""CustomerID""], ""alFkI"", true))"); } + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Case_sensitive_string_comparison_instance(bool async) + { + await AssertQuery( + async, + ss => ss.Set().Where(c => c.CustomerID.Equals("ALFKI", StringComparison.Ordinal)), + entryCount: 1); + + AssertSql( + @"SELECT c +FROM root c +WHERE ((c[""Discriminator""] = ""Customer"") AND STRINGEQUALS(c[""CustomerID""], ""ALFKI"", false))"); + } + + [ConditionalTheory] + [MemberData(nameof(IsAsyncData))] + public virtual async Task Case_sensitive_string_comparison_static(bool async) + { + await AssertQuery( + async, + ss => ss.Set().Where(c => string.Equals(c.CustomerID, "ALFKI", StringComparison.Ordinal)), + entryCount: 1); + + AssertSql( + @"SELECT c +FROM root c +WHERE ((c[""Discriminator""] = ""Customer"") AND STRINGEQUALS(c[""CustomerID""], ""ALFKI"", false))"); + } + private void AssertSql(params string[] expected) => Fixture.TestSqlLoggerFactory.AssertBaseline(expected);