-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
SQL Server: Translate statistics aggregate functions #28104
Comments
* string.Join (SQL Server and SQLite) * string.Concat (SQL Server and SQLite) * Standard deviation and variance (SQL Server) Closes dotnet#2981 Closes dotnet#28104
@lauxjpn you may be interested in this for MySQL, though I'd hold off for a little while before implementing, since the infrastructure is still being locked down. PostgreSQL issue: npgsql/efcore.pg#532 |
The design problem outlined by @smitpatel is what to do with top-level versions of these attributes. For example, the PR as it currently is only allows expressing standard deviation as follows: _ = context.Products
.GroupBy(od => od.ProductID)
.Select(g => new
{
ProductID = g.Key,
StandardDeviation = EF.Functions.StandardDeviationSample(g.Select(od => od.UnitPrice)),
}); ... but does not allow top-level usage: _ = context.Products.Select(p => p.UnitPrice).StandardDeviation();
// or even possibly:
_ = context.Products.StandardDeviation(p => p.UnitPrice); We have 3 options here: The top-level variant(s) above would be extension methods over
_ = EF.Functions.StandardDeviationSample(context.Products.Select(p => p.UnitPrice)); Note that this question is general for custom aggregates, and not specific to these statistics ones. We should look at what EF6 did here to maybe get inspiration. |
I thought of an argument in favor of option 1, i.e. have different syntaxes for Enumerable and IQueryable (top-level) versions of the aggregate function. For cases where we translate a built-in .NET method, e.g. string.Join, the top-level method will in any case have to be different from the Enumerable version. We could have an IQueryable extension method: ctx.Blogs.Where(...).Select(b => b.Name).StringJoin(", ");
// or better:
ctx.Blogs.Where(...).StringJoin(b => b.Name, ", "); ... or if we don't want an extension over IQueryable, an EF.Function: EF.Functions.StringJoin(", ", ctx.Blogs.Where(...)); ... but in any case it's not going to be the same as the enumerable string.Join. We'll have the same case with the spatial methods (#13278). So if we have this problem in any case when it comes to built-in .NET methods we translate, it may be OK to just always have it, and have a nice IQueryable extension for the top-level, and an EF.Functions for the enumerable version. |
* string.Join (SQL Server and SQLite) * string.Concat (SQL Server and SQLite) * Standard deviation and variance (SQL Server) Closes dotnet#2981 Closes dotnet#28104
* string.Join (SQL Server and SQLite) * string.Concat (SQL Server and SQLite) * Standard deviation and variance (SQL Server) Closes dotnet#2981 Closes dotnet#28104
* string.Join (SQL Server and SQLite) * string.Concat (SQL Server and SQLite) * Standard deviation and variance (SQL Server) Closes dotnet#2981 Closes dotnet#28104
With #22957 done, we can now add translations for additional aggregate operators.
Detailed investigation across databases
SQL Server
PostgreSQL
MariaDB
The text was updated successfully, but these errors were encountered: