You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the only supported function is ROW_NUMBER but even this function is not supported directly, it's only used internally by the Query pipeline in certain scenarios.
For example PERCENTILE_CONT or PERCENTILE_DISC are analytic functions which can be used to calculated the median of a dateset. An operation which is overly complicated using other query methods.
Example 1 of Median calculation with Pure SQL:
SELECT
(
(SELECTMAX(Score) FROM
(SELECT TOP 50 PERCENT Score FROM Posts ORDER BY Score) AS BottomHalf)
+
(SELECTMIN(Score) FROM
(SELECT TOP 50 PERCENT Score FROM Posts ORDER BY Score DESC) AS TopHalf)
) /2AS Median
Example 2 of Median calculation with PERCENTILE_CONT
SELECT TOP 1 PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY Score) OVER (PARTITION BY null) As Median FROM Posts
The first query is very hard to translate into Linq (As SELECT TOP PERCENT is not supported). It requires to query the count first, then query the max value from top half and the min value from bottom half and average them)
Desired solution:
Accessing the SQL Server Analytic functions could be done using the EF.Functions extensions:
Translating to PERCENTILE_CONT should be partially possible once we have support for custom provider aggregate functions (#22957). The partition notably wouldn't be covered (this is probably related to window functions, #12747).
Add support for SQL Server Analytic Functions
Currently the only supported function is
ROW_NUMBER
but even this function is not supported directly, it's only used internally by the Query pipeline in certain scenarios.For example
PERCENTILE_CONT
orPERCENTILE_DISC
are analytic functions which can be used to calculated the median of a dateset. An operation which is overly complicated using other query methods.Example 1 of Median calculation with Pure SQL:
Example 2 of Median calculation with
PERCENTILE_CONT
The first query is very hard to translate into Linq (As SELECT TOP PERCENT is not supported). It requires to query the count first, then query the max value from top half and the min value from bottom half and average them)
Desired solution:
Accessing the SQL Server Analytic functions could be done using the
EF.Functions
extensions:Example:
The above Linq expression would translate to Example 2 SQL.
Dependencies:
The text was updated successfully, but these errors were encountered: