-
Notifications
You must be signed in to change notification settings - Fork 232
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
Improve S2971 message to use AsEnumerable in LINQ database query #3604
Comments
Hi @mitchello , Can you please provide some small, but complete reproducer for this case? I tried to reproduce it with similar select-to-local-class but EF 3.1.8 handled that without an exception. |
Hi @pavel-mikula-sonarsource , you will find a small project reproducing our issue. Here's some more information regarding this behavior : https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.x/#linq-overhaul |
Hi @mitchello, Thank you for the reproducer project. I'm able to reproduce the issue now. While looking at the example, you don't really need So the intention and core implementation of the rule is correct. I've updated the rule specification with note about this specific case we'll try to improve the message in this case to suggest |
Hi @pavel-mikula-sonarsource, Regards |
ToDo:
|
Description
S2971
When calling ToList or ToArray in the middle of a LINQ chain, the rule raised, which is correct in a way but there is an exception that should be managed. When using Entity Framework Core (3.x), it's recommended to manage data on client side as some features can't be parse into SQL.
See: https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.x/breaking-changes#linq-queries-are-no-longer-evaluated-on-the-client
Repro steps
Using EF Core:
return portLinq.OrderBy(v => v.Date).ToList().Select(x => new HistoricalValue(x.Date, x.Value)).ToList();
If we don't retrieve data on client side with the ToList in the middle of the chain, the Select will throw an exception at runtime as it's impossible for EF Core to parse what's in the Select statement.
Expected behavior
Rule shouldn't be raised
Actual behavior
Rule raised
The text was updated successfully, but these errors were encountered: