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

[SMALL] Fix to #29572 - Json: predicate on json bool property generates incorrect sql #29574

Merged
1 commit merged into from
Nov 16, 2022
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 @@ -764,5 +764,5 @@ protected override Expression VisitUpdate(UpdateExpression updateExpression)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override Expression VisitJsonScalar(JsonScalarExpression jsonScalarExpression)
=> jsonScalarExpression;
=> ApplyConversion(jsonScalarExpression, condition: false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,36 @@ public virtual Task Json_all_types_projection_individual_properties(bool async)
x.Reference.TestNullableEnumWithConverterThatHandlesNulls,
}));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Json_boolean_predicate(bool async)
=> AssertQuery(
async,
ss => ss.Set<JsonEntityAllTypes>().Where(x => x.Reference.TestBoolean),
entryCount: 6);

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Json_boolean_predicate_negated(bool async)
=> AssertQuery(
async,
ss => ss.Set<JsonEntityAllTypes>().Where(x => !x.Reference.TestBoolean),
entryCount: 0);

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Json_boolean_projection(bool async)
=> AssertQueryScalar(
async,
ss => ss.Set<JsonEntityAllTypes>().Select(x => x.Reference.TestBoolean));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Json_boolean_projection_negated(bool async)
=> AssertQueryScalar(
async,
ss => ss.Set<JsonEntityAllTypes>().Select(x => !x.Reference.TestBoolean));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task FromSql_on_entity_with_json_basic(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,55 @@ FROM [JsonEntitiesAllTypes] AS [j]
""");
}

public override async Task Json_boolean_predicate(bool async)
{
await base.Json_boolean_predicate(async);

AssertSql(
"""
SELECT [j].[Id], [j].[Collection], [j].[Reference]
FROM [JsonEntitiesAllTypes] AS [j]
WHERE CAST(JSON_VALUE([j].[Reference],'$.TestBoolean') AS bit) = CAST(1 AS bit)
""");
}

public override async Task Json_boolean_predicate_negated(bool async)
{
await base.Json_boolean_predicate_negated(async);

AssertSql(
"""
SELECT [j].[Id], [j].[Collection], [j].[Reference]
FROM [JsonEntitiesAllTypes] AS [j]
WHERE CAST(JSON_VALUE([j].[Reference],'$.TestBoolean') AS bit) = CAST(0 AS bit)
""");
}

public override async Task Json_boolean_projection(bool async)
{
await base.Json_boolean_projection(async);

AssertSql(
"""
SELECT CAST(JSON_VALUE([j].[Reference],'$.TestBoolean') AS bit)
FROM [JsonEntitiesAllTypes] AS [j]
""");
}

public override async Task Json_boolean_projection_negated(bool async)
{
await base.Json_boolean_projection_negated(async);

AssertSql(
"""
SELECT CASE
WHEN CAST(JSON_VALUE([j].[Reference],'$.TestBoolean') AS bit) = CAST(0 AS bit) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END
FROM [JsonEntitiesAllTypes] AS [j]
""");
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public override async Task FromSql_on_entity_with_json_basic(bool async)
Expand Down