Open roji opened 2 years ago
One additional idea from @divega: define a new “SelectOne” operator that would be essentially a shortcut for GroupBy(constant).Select().
Note: remember we have FromExpression for mapping TVFs which is somewhat related, docs (again thanks @divega).
Note #30538 which is a partial dup of this.
2981, #28104 and #13278 introduced various aggregate operators, but only IEnumerable versions. This means that they can be used with GroupBy:
... but cannot be used at the query top-level - without GroupBy - where IQueryable versions would be required. The team discussed this and decided to punt the top-level operators out of 7.0, and revisit this based on user feedback.
Workaround
In the meantime, users can work around this gap by grouping over a constant:
Design discussion
See original discussion in https://github.com/dotnet/efcore/issues/28104#issuecomment-1142427678 on how to represent the top-level operators. Options include:
Extension over IQueryable
EF.Functions
Context.Query
We have an "unrelated" feature to generally allow expressing queries within a lambda (ISSUE NEEDED):
Note: Infra for top-level aggregates was done in #28102 Note: See https://github.com/npgsql/efcore.pg/issues/727 for the Npgsql epic covering PG aggregate operators - we'd have to do the same for those.