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

Query: Fix bug in CaseExpression.VisitChildren #21938

Merged
1 commit merged into from
Aug 4, 2020
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
4 changes: 3 additions & 1 deletion src/EFCore.Relational/Query/SqlExpressions/CaseExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ protected override Expression VisitChildren(ExpressionVisitor visitor)
changed |= elseResult != ElseResult;

return changed
? new CaseExpression(operand, whenClauses, elseResult)
? operand == null
? new CaseExpression(whenClauses, elseResult)
: new CaseExpression(operand, whenClauses, elseResult)
: this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4155,6 +4155,12 @@ public override Task Max_on_empty_sequence_throws(bool async)
return base.Max_on_empty_sequence_throws(async);
}

[ConditionalTheory(Skip = "string.IndexOf Issue#17246")]
public override Task Distinct_followed_by_ordering_on_condition(bool async)
{
return base.Distinct_followed_by_ordering_on_condition(async);
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6099,5 +6099,22 @@ public virtual Task Pending_selector_in_cardinality_reducing_method_is_applied_b
}),
assertOrder: true);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Distinct_followed_by_ordering_on_condition(bool async)
{
var searchTerm = "c";
return AssertQuery(
async,
ss => ss.Set<Customer>()
.Where(c => c.CustomerID != "VAFFE" && c.CustomerID != "DRACD")
.Select(e => e.City)
.Distinct()
.OrderBy(x => x.IndexOf(searchTerm))
.ThenBy(x => x)
.Take(5),
assertOrder: true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5222,6 +5222,26 @@ WHERE [c1].[CustomerID] LIKE N'F%'
ORDER BY [c1].[CustomerID]");
}

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

AssertSql(
@"@__p_1='5'
@__searchTerm_0='c' (Size = 4000)

SELECT TOP(@__p_1) [t].[City]
FROM (
SELECT DISTINCT [c].[City]
FROM [Customers] AS [c]
WHERE [c].[CustomerID] NOT IN (N'VAFFE', N'DRACD')
) AS [t]
ORDER BY CASE
WHEN @__searchTerm_0 = N'' THEN 0
ELSE CAST(CHARINDEX(@__searchTerm_0, [t].[City]) AS int) - 1
END, [t].[City]");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down