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

Fix to #30326 - Query: converter from bool used in predicate without comparison fails on sqlite (and other non-sql server backends?) #30666

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ private Expression VisitLeftJoin(LeftJoinExpression leftJoinExpression)
[return: NotNullIfNotNull("sqlExpression")]
private SqlExpression? TryCompensateForBoolWithValueConverter(SqlExpression? sqlExpression)
{
if (sqlExpression is ColumnExpression columnExpression
&& columnExpression.TypeMapping!.ClrType == typeof(bool)
&& columnExpression.TypeMapping.Converter != null)
if ((sqlExpression is ColumnExpression or JsonScalarExpression)
&& sqlExpression.TypeMapping!.ClrType == typeof(bool)
&& sqlExpression.TypeMapping.Converter != null)
{
return _sqlExpressionFactory.Equal(
sqlExpression,
Expand Down
24 changes: 18 additions & 6 deletions test/EFCore.Sqlite.FunctionalTests/Query/JsonQuerySqliteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,40 @@ await AssertQuery(
""");
}

[ConditionalTheory(Skip = "issue #30326")]
public override async Task Json_predicate_on_bool_converted_to_int_zero_one(bool async)
{
await base.Json_predicate_on_bool_converted_to_int_zero_one(async);

AssertSql();
AssertSql(
"""
SELECT "j"."Id", "j"."Reference"
FROM "JsonEntitiesConverters" AS "j"
WHERE json_extract("j"."Reference", '$.BoolConvertedToIntZeroOne') = 1
""");
}

[ConditionalTheory(Skip = "issue #30326")]
public override async Task Json_predicate_on_bool_converted_to_string_True_False(bool async)
{
await base.Json_predicate_on_bool_converted_to_string_True_False(async);

AssertSql();
AssertSql(
"""
SELECT "j"."Id", "j"."Reference"
FROM "JsonEntitiesConverters" AS "j"
WHERE json_extract("j"."Reference", '$.BoolConvertedToStringTrueFalse') = 'True'
""");
}

[ConditionalTheory(Skip = "issue #30326")]
public override async Task Json_predicate_on_bool_converted_to_string_Y_N(bool async)
{
await base.Json_predicate_on_bool_converted_to_string_Y_N(async);

AssertSql();
AssertSql(
"""
SELECT "j"."Id", "j"."Reference"
FROM "JsonEntitiesConverters" AS "j"
WHERE json_extract("j"."Reference", '$.BoolConvertedToStringYN') = 'Y'
""");
}

private void AssertSql(params string[] expected)
Expand Down