DataObjects-NET / dataobjects-net

https://dataobjects.net
MIT License
60 stars 23 forks source link

Fixes translation issue of calculated expression with conditional expressions #377

Closed alex-kulakov closed 4 months ago

alex-kulakov commented 4 months ago

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);