Repository navigation
Throwing First/Single terminals, and ToDictionary with a value selector - #126
Merged
Merged
Conversation
…ary takes a value selector The throwing terminals are on every mapped query (and FirstAsync<T>/SingleAsync<T> on commands); they read like the OrDefault forms and throw after cleanup. ToDictionary and ToDictionaryAsync take a key and a value selector and build the dictionary in one pass. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…interface extensions guard a null query Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…t interface terminals, no un-awaited ValueTask Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Conflicts: the SingleResult wording in mapping.md and the MappedQuery remarks keep master's text with this branch's First and Single additions; whats-new keeps both sets of bullets. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Conflicts: First/Single and Select are both added at the end of MappedQueryExtensions, so both are kept; the public-API list, the notes and the samples keep both sides. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Throwing
First/Singleterminals, andToDictionarywith a value selector, on every mapped query.What
First(),Single(),FirstAsync(ct)andSingleAsync(ct)are onMappedQuery<T>, its two staging structs,MappedReader<T>,MappedCommand<T>andMappedTable<T>, and as extensions onIMappedQuery<T>.FirstthrowsInvalidOperationExceptionon no rows;Singlealso throws on more than one row. The message names the terminal.FirstAsync<T>andSingleAsync<T>are on commands too, next to the existingFirstOrDefaultAsync<T>.FirstOrDefaultandSingleOrDefault:Firstasks the provider for one row andSingledoes not; the later result sets are read through unless.SingleResult(); the connection is closed only if the call opened it. The throw happens after that cleanup, so a failure in a later result set is thrown first, andSingle's more-than-one error is never replaced.ToDictionary(keySelector, valueSelector, comparer)andToDictionaryAsync(...)build the dictionary in one pass, key selector before value selector, once per row, with the same duplicate-key behavior as the key-only form (ArgumentException).IMappedQuery<T>interface the same terminals now do what the members do for the library's six types: the library's message and the read-through of later result sets. A third-party implementation of the interface still works through a LINQ fallback, which cannot read through. (Found in review: before this,IMappedQuery<Post> q = ...; q.FirstOrDefault()stopped after the row and missed a later failure.) The interface extensions also guard a null query now.Notes for review
ToDictionaryAsynckeeps the comparer before the token, as the key-only form does, so a caller passes the token by name.Docs and tests
SingleAsync, a lookup with a value selector).SingleResult, a third-party implementation, null query), and for the dictionary overloads (one pass, comparer, duplicate key, a throwing selector leaves no leak).Checks
TokenTerminalTests.Allocation_Channel, a known flaky test (a different shape each run) that this change does not touch and that is being fixed separately. Samples: 109 of 109 checks pass. Style and analyzers: 0 findings. DocFX: 0 warnings.🤖 Generated with Claude Code