A query is turned into a list or enumerable and then filtered, so the filter runs in memory and not in the database
What it finds
query.ToList().Where(...) and query.AsEnumerable().Where(...) load every row first and filter afterwards. On an Entity Framework query, putting Where before ToList lets the database filter. On in-memory collections the order does not matter much, which the rule cannot tell apart, so it is strict.
From the rule's source, filter_after_materializing.rs.
using System.Linq; class Reports{ int Count(IQueryable<int> orders) => orders.ToList().Where(o => o > 10).Count();tx0 reports: Where runs after ToList, in memory int Better(IQueryable<int> orders) => orders.Where(o => o > 10).Count();} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:filter-after-materializing" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:filter-after-materializing] reason="..."tx0 explain tx0/csharp:filter-after-materializing shows the same in the terminal. Found a false positive? Report it.