Skip to content

Commit

Permalink
Fix to #30326 - Query: converter from bool used in predicate without …
Browse files Browse the repository at this point in the history
…comparison fails on sqlite (and other non-sql server backends?)

RelationalValueConverterCompensatingExpressionVisitor was not compensating for bool values with converters for JsonScalarExpression.

Fixes #30326
  • Loading branch information
maumar committed Apr 12, 2023
1 parent 6e1ab07 commit 330b7da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
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 || sqlExpression is 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

0 comments on commit 330b7da

Please sign in to comment.