-
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
EF Core 7 - FirstWithoutOrderByAndFilterWarning in simple query with multiple aggregate functions #29782
Comments
1 similar comment
Sorry for taking so long to look at this. AFAIK, the pattern of using group-by-constant is indeed the only way to achieve querying the results of multiple aggregate operators. We've had discussions on a better API to allow expressing this more elegantly, but as of now that's the recommend way (unless I'm missing something). As for the warning, I'd avoid it by simply using Single rather than First; that also conveys what you're doing better, clearly saying you expect just one result (rather than saying you want the first). This would change the SQL to have As for the warning, technically it's true that we shouldn't warn, but identifying the precise pattern where the warning shouldn't be issued may be non-trivial; as the value is generally very low and Single seems more suited to this task, I don't see us working on this any time soon... Let me know if this answers your questions and don't hesitate to ask for more clarifications. |
Thank you, I hadn't considered using .Single(): I agree it's better, both in terms of readability and (probably) performance. I will do that. |
In order to perform a simple query with multiple aggregate functions in the select, such as:
I am using "group by (constant value)":
I noted that in EF7 this produces warning CoreEventId.FirstWithoutOrderByAndFilterWarning ("The query uses the 'First'/'FirstOrDefault' operator without 'OrderBy' and filter operators. ...").
Questions
Example console app
Output of the example app
Provider and version information
EF Core version: 7.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 7.0
The text was updated successfully, but these errors were encountered: