Fix to #18916 - Query: regression in EFCore 3.1 Preview 2 and Preview3 for query with conditional expression whose element is a comparison containing null-value parameter #18937
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem was that now we are peeking into parameter values and simplifying the queries. As a result comparisons of non-nullable expressions with null-value parameter are optimized out to a simple constant false. Sql server expects search condition in some places (e.g. WHERE, HAVING or WHEN parts of CASE statements).
Before we look into parameter values we run SearchConditionConvertingExpressionVisitor which fixes those cases. However, this visitor is currently sql server specific, and the part of the pipeline that looks into parameter values is not provider specific, so we can't re-run it.
Fix is to manually convert constants encountered in those areas into conditions. We used to do it already for WHERE and HAVING but we missed WHEN.
Resolves #18916