Skip to content

Conversation

@alex-kulakov
Copy link
Contributor

Some conditional expressions are not translated into SqlCase, but to SqlVariant, at the same time other providers use SqlCase successfully.

This led to wrong result SQL query text in many parts, like ORDER BY, GROUP BY. This happened because instead of entire expression postprocessor as expected chose either of two branches of SqlVariant. For example, for query like

session.Query.All<SomeTable>().OrderBy(e=> e.MultiplyCoefficient * (e.SomeEntityRef == localEntityRef ? 2 : 1));

it led to something static value of 2 instead of expression which should be applied to every row in results, similar to this

SELECT *
FROM "SomeTable" "a"
ORDER BY "a"."MultiplyCoefficient" * 2;

when correct SQL text should be similar to this

SELECT *
FROM "SomeTable" "a"
ORDER BY "a"."MultiplyCoefficient" * (CASE WHEN  "a"."SomeEntityRef.Id" = @p0_1 THEN 2 ELSE 1 END);

This lead to full expression in, for instance, ORDER BY clause
like all other RDBMS
index filter builder uses Expression processor, just in case we should have
such test case
- save some memory on booleans by using flags
- fields region structure is more clear
- ctor structure improved
- Prevent test of conditional expression fail on SQL Server because the
  storage has no support of CASE statement within WHERE part
- Added extra cases for entity fields comparison to cover all supported
  cases
- Added case of two entity references comparison
@alex-kulakov alex-kulakov merged commit 7193d7a into 6.0 Feb 21, 2024
@alex-kulakov alex-kulakov deleted the 6.0-pgsql-calculated-exp-issue branch February 21, 2024 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants