Repository navigation
feat: CMTK0009 reports a delegate condition that reads a whole query - #137
Merged
Merged
Conversation
FirstOrNone, SingleOrNone and FirstOrError on an IQueryable<T> take the condition as an Expression. A Func variable, field or property, a method group, an anonymous method or a call that returns a Func binds the call to the IEnumerable<T> overload, which reads every row and runs the condition in memory. CMTK0009 (still a Warning, decision 34) now reports it with a message of its own that names the overload it fell to. A lambda at the call, an Expression variable or field, and a receiver typed as a sequence (AsEnumerable(), a cast, an IEnumerable<T> local) stay silent. The receiver is a query when it is IQueryable<T>, implements it, or is a type parameter constrained to it, through any bound. Variant analysis found two siblings: LastOrNone and LastOrError given a delegate on a query bind to the sequence overload the same way, while their query overloads refuse to compile. Both are reported, with advice to order the other way and take the first. The new catalogue Variants/QueryDelegateShapes holds the receivers (how a query is typed, and the call shapes of TypeArgumentSites that move the receiver: null-conditional, lowered static form, in a lambda) against every condition and lookup. QueryDelegateConditionTests sweeps it, and TypeArgumentKinds for the element type, and EF Core's DbSet. Six seeds are each caught: no query check, no type-parameter bound, no unwrap of the implicit conversion, explicit casts unwrapped too, no AllInterfaces, and the lowered form's receiver dropped. No code fix: the condition's rewrite is the author's (issue comment). Closes #129 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…odoMetis.TypeKit into feat/cmtk0009-query-delegate # Conflicts: # CHANGELOG.md
CaffeinatedCoder
added a commit
that referenced
this pull request
Oct 29, 2026
Both changelog lines kept: #137's CMTK0009 entry and the docs site's. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #129
Problem
FirstOrNone,SingleOrNoneandFirstOrErroron anIQueryable<T>bind to the query's overload only when the condition is a lambda written at the call. AFunc<T, bool>in a variable, a field or a property, a method group, an anonymous method or a call that returns aFuncbinds to theIEnumerable<T>overload instead. EF Core then reads every row and runs the condition in memory, and nothing warned.QueryOptionTestspinned the behaviour, and the docs said "without a warning".Change
DefaultProducingCallAnalyzer: a second CMTK0009 descriptor (same id, same Warning severity, decision 34) with its own message:'FirstOrNone' on the query binds to its IEnumerable<T> overload, since the condition is a 'Func<Shipment, bool>' and not an expression: it reads every row and runs the condition in memory. .... The sequence overloads that take aFuncare resolved by symbol from TypeKit's ownOption/Resultclasses (TypeKitSymbols.ResultClassMethodsis new, besideOptionClassMethods). The receiver, after the compiler's implicit conversion is unwrapped, counts as a query when it isIQueryable<T>, implements it, or is a type parameter constrained to it. An explicit cast andAsEnumerable()stay silent.LastOrNoneandLastOrErrorgiven a delegate on a query read every row the same way, while their query overloads refuse to compile. They are reported too, with advice to order the other way and take the first.AsEnumerable()only silences the warning.Samples/Analyzers/QueryConditionSamples.cs), and the rule table row. The EF README, the base README,docs/option.mdanddocs/ef-core.mdno longer say "without a warning".QueryOptionTests' summary names the rule.design/analyzers.md's row, the roadmap item removed from "Gaps, in any 2.x", a changelog line, and claimsQ01–Q05intest/oracles/claims.json.Tests
QueryDelegateConditionTests: exact messages for all five lookups, the silent forms, EF Core'sDbSet<T>andSet<T>(). A sweep over the new catalogueVariants/QueryDelegateShapescrosses 22 receivers (how a query is typed, and theTypeArgumentSitescall shapes that move the receiver: null-conditional, the lowered static form, in a lambda, against sequences that are no query) with 17 conditions (12 delegate forms, 5 lambda or expression forms) and every lookup. A second sweep runs everyTypeArgumentKindselement type. 104 cases in all.List<T>for a query fails the silent test), no type-parameter bound (2 rows), no unwrap of the implicit conversion (95), explicit casts unwrapped too (the cast row), noAllInterfaces(95), and the lowered static form's receiver dropped (3).🤖 Generated with Claude Code