Skip to content
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 @@ -374,6 +374,18 @@ protected override Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpressio
case ExpressionType.Not
when sqlUnaryExpression.Type == typeof(bool):
{
// when possible, avoid converting to/from predicate form
if (!_isSearchCondition && sqlUnaryExpression.Operand is not (ExistsExpression or InExpression or LikeExpression))
{
var negatedOperand = (SqlExpression)Visit(sqlUnaryExpression.Operand);
return _sqlExpressionFactory.MakeBinary(
ExpressionType.ExclusiveOr,
negatedOperand,
_sqlExpressionFactory.Constant(true, negatedOperand.TypeMapping),
negatedOperand.TypeMapping
)!;
}

_isSearchCondition = true;
resultCondition = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,14 @@ public virtual Task Select_inverted_boolean(bool async)
w => new { w.Id, Manual = !w.IsAutomatic }),
elementSorter: e => e.Id);

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Select_inverted_nullable_boolean(bool async)
=> AssertQuery(
async,
ss => ss.Set<LocustHorde>().Select(w => new { w.Id, Alive = !w.Eradicated }),
elementSorter: e => e.Id);

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task Select_comparison_with_null(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1676,10 +1676,7 @@ public override async Task Conditional_expression_with_conditions_does_not_colla
AssertSql(
"""
SELECT CASE
WHEN [c0].[Id] IS NOT NULL THEN CASE
WHEN [c0].[Processed] = CAST(0 AS bit) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END
WHEN [c0].[Id] IS NOT NULL THEN [c0].[Processed] ^ CAST(1 AS bit)
ELSE NULL
END AS [Processing]
FROM [Carts] AS [c]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,15 +770,23 @@ public override async Task Select_inverted_boolean(bool async)

AssertSql(
"""
SELECT [w].[Id], CASE
WHEN [w].[IsAutomatic] = CAST(0 AS bit) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END AS [Manual]
SELECT [w].[Id], [w].[IsAutomatic] ^ CAST(1 AS bit) AS [Manual]
FROM [Weapons] AS [w]
WHERE [w].[IsAutomatic] = CAST(1 AS bit)
""");
}

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

AssertSql(
"""
SELECT [f].[Id], [f].[Eradicated] ^ CAST(1 AS bit) AS [Alive]
FROM [Factions] AS [f]
""");
}

public override async Task Select_comparison_with_null(bool async)
{
await base.Select_comparison_with_null(async);
Expand Down Expand Up @@ -5168,12 +5176,9 @@ public override async Task Negated_bool_ternary_inside_anonymous_type_in_project
AssertSql(
"""
SELECT CASE
WHEN CASE
WHEN [g].[HasSoulPatch] = CAST(1 AS bit) THEN CAST(1 AS bit)
ELSE COALESCE([g].[HasSoulPatch], CAST(1 AS bit))
END = CAST(0 AS bit) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END AS [c]
WHEN [g].[HasSoulPatch] = CAST(1 AS bit) THEN CAST(1 AS bit)
ELSE COALESCE([g].[HasSoulPatch], CAST(1 AS bit))
END ^ CAST(1 AS bit) AS [c]
FROM [Tags] AS [t]
LEFT JOIN [Gears] AS [g] ON [t].[GearNickName] = [g].[Nickname] AND [t].[GearSquadId] = [g].[SquadId]
""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2344,10 +2344,7 @@ public override async Task Json_boolean_projection_negated(bool 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
SELECT CAST(JSON_VALUE([j].[Reference], '$.TestBoolean') AS bit) ^ CAST(1 AS bit)
FROM [JsonEntitiesAllTypes] AS [j]
""");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,15 +1138,23 @@ public override async Task Select_inverted_boolean(bool async)

AssertSql(
"""
SELECT [w].[Id], CASE
WHEN [w].[IsAutomatic] = CAST(0 AS bit) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END AS [Manual]
SELECT [w].[Id], [w].[IsAutomatic] ^ CAST(1 AS bit) AS [Manual]
FROM [Weapons] AS [w]
WHERE [w].[IsAutomatic] = CAST(1 AS bit)
""");
}

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

AssertSql(
"""
SELECT [l].[Id], [l].[Eradicated] ^ CAST(1 AS bit) AS [Alive]
FROM [LocustHordes] AS [l]
""");
}

public override async Task Select_comparison_with_null(bool async)
{
await base.Select_comparison_with_null(async);
Expand Down Expand Up @@ -7050,12 +7058,9 @@ public override async Task Negated_bool_ternary_inside_anonymous_type_in_project
AssertSql(
"""
SELECT CASE
WHEN CASE
WHEN [u].[HasSoulPatch] = CAST(1 AS bit) THEN CAST(1 AS bit)
ELSE COALESCE([u].[HasSoulPatch], CAST(1 AS bit))
END = CAST(0 AS bit) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END AS [c]
WHEN [u].[HasSoulPatch] = CAST(1 AS bit) THEN CAST(1 AS bit)
ELSE COALESCE([u].[HasSoulPatch], CAST(1 AS bit))
END ^ CAST(1 AS bit) AS [c]
FROM [Tags] AS [t]
LEFT JOIN (
SELECT [g].[Nickname], [g].[SquadId], [g].[HasSoulPatch]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,15 +970,24 @@ public override async Task Select_inverted_boolean(bool async)

AssertSql(
"""
SELECT [w].[Id], CASE
WHEN [w].[IsAutomatic] = CAST(0 AS bit) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END AS [Manual]
SELECT [w].[Id], [w].[IsAutomatic] ^ CAST(1 AS bit) AS [Manual]
FROM [Weapons] AS [w]
WHERE [w].[IsAutomatic] = CAST(1 AS bit)
""");
}

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

AssertSql(
"""
SELECT [f].[Id], [l].[Eradicated] ^ CAST(1 AS bit) AS [Alive]
FROM [Factions] AS [f]
INNER JOIN [LocustHordes] AS [l] ON [f].[Id] = [l].[Id]
""");
}

public override async Task Select_comparison_with_null(bool async)
{
await base.Select_comparison_with_null(async);
Expand Down Expand Up @@ -5959,12 +5968,9 @@ public override async Task Negated_bool_ternary_inside_anonymous_type_in_project
AssertSql(
"""
SELECT CASE
WHEN CASE
WHEN [s].[HasSoulPatch] = CAST(1 AS bit) THEN CAST(1 AS bit)
ELSE COALESCE([s].[HasSoulPatch], CAST(1 AS bit))
END = CAST(0 AS bit) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END AS [c]
WHEN [s].[HasSoulPatch] = CAST(1 AS bit) THEN CAST(1 AS bit)
ELSE COALESCE([s].[HasSoulPatch], CAST(1 AS bit))
END ^ CAST(1 AS bit) AS [c]
FROM [Tags] AS [t]
LEFT JOIN (
SELECT [g].[Nickname], [g].[SquadId], [g].[HasSoulPatch]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3012,15 +3012,23 @@ public override async Task Select_inverted_boolean(bool async)

AssertSql(
"""
SELECT [w].[Id], CASE
WHEN [w].[IsAutomatic] = CAST(0 AS bit) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END AS [Manual]
SELECT [w].[Id], [w].[IsAutomatic] ^ CAST(1 AS bit) AS [Manual]
FROM [Weapons] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [w]
WHERE [w].[IsAutomatic] = CAST(1 AS bit)
""");
}

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

AssertSql(
"""
SELECT [f].[Id], [f].[Eradicated] ^ CAST(1 AS bit) AS [Alive]
FROM [Factions] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [f]
""");
}

public override async Task Where_datetimeoffset_millisecond_component(bool async)
{
await base.Where_datetimeoffset_millisecond_component(async);
Expand Down Expand Up @@ -4413,12 +4421,9 @@ public override async Task Negated_bool_ternary_inside_anonymous_type_in_project
AssertSql(
"""
SELECT CASE
WHEN CASE
WHEN [g].[HasSoulPatch] = CAST(1 AS bit) THEN CAST(1 AS bit)
ELSE COALESCE([g].[HasSoulPatch], CAST(1 AS bit))
END = CAST(0 AS bit) THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END AS [c]
WHEN [g].[HasSoulPatch] = CAST(1 AS bit) THEN CAST(1 AS bit)
ELSE COALESCE([g].[HasSoulPatch], CAST(1 AS bit))
END ^ CAST(1 AS bit) AS [c]
FROM [Tags] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [t]
LEFT JOIN [Gears] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [g] ON [t].[GearNickName] = [g].[Nickname] AND [t].[GearSquadId] = [g].[SquadId]
""");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6157,6 +6157,17 @@ public override async Task Select_inverted_boolean(bool async)
""");
}

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

AssertSql(
"""
SELECT "f"."Id", NOT ("f"."Eradicated") AS "Alive"
FROM "Factions" AS "f"
""");
}

public override async Task Multiple_orderby_with_navigation_expansion_on_one_of_the_order_bys(bool async)
{
await base.Multiple_orderby_with_navigation_expansion_on_one_of_the_order_bys(async);
Expand Down