Skip to content

Support common collection return types for multi-row queries - #68

Merged
twogood merged 4 commits into
mainfrom
copilot/support-common-collection-types
Oct 12, 2026
Merged

twogood merged 4 commits into
mainfrom
copilot/support-common-collection-types

Conversation

Copilot AI commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

MethodHandler only treated an exact IEnumerable<T> return as a multi-row query. Methods returning IReadOnlyList<T>, List<T>, T[] and similar were handled as single-row results, so callers had to return IEnumerable<T> and call .ToList() themselves.

[SqlQuery("SELECT * FROM user ORDER BY id")]
Task<IReadOnlyList<User>> ListUsers();   // previously treated as a single-row result

[SqlQuery("SELECT * FROM user ORDER BY id")]
User[] ListUsersArray();

Changes (Implementation/MethodHandler.cs)

  • Detection: the return type, or the Task<T> payload, is multi-row if it is one of IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>, List<T> or a single-dimension T[]. This is a match on the generic type definition, not on assignability. That keeps string and user types that merely implement IEnumerable<T> as single values.
  • Materialization: the gateway contract is unchanged and still returns IEnumerable<object>. The result is cast to T. IEnumerable<T> stays lazy. Everything else is copied into a List<T>, or into an array for T[].
  • Rejection: other generic types in System.Collections.* that implement IEnumerable<>, such as HashSet<T> and Dictionary<,>, now throw NotSupportedException when the DAO is built. The message lists the supported types. The repo has no configuration-exception type, so I reused NotSupportedException, which DatabaseClient already throws for a missing SQL attribute.

Review notes

  • byte[] and multi-dimensional arrays are deliberately not treated as collections, so blob columns still map to a single value.
  • Scalar element casts still go through Enumerable.Cast, so they behave as before. SQLite returns integers as long, so List<int> over SELECT id throws InvalidCastException. The new tests use List<long>.
  • New CollectionReturnTypesTest.cs covers each supported type in sync and async form, empty and non-empty result sets, nullable elements, and rejection of HashSet<T>.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d2bcf243-6ffa-4a78-9a43-c84837c35bcd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI linked an issue Oct 12, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Support common collection return types for multi-row queries Support common collection return types for multi-row queries Oct 12, 2026
Copilot AI requested a review from twogood October 12, 2026 11:00
@twogood
twogood requested a balanced review from Copilot October 12, 2026 11:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Reflection masks cast exceptions, and unsupported types are rejected on invocation rather than during DAO construction as described.

2 open findings
What changed in this PR

Adds support for common multi-row collection return types in DAO query methods.

Changes:

  • Detects supported generic collections and one-dimensional arrays.
  • Materializes results as lists or arrays while preserving lazy IEnumerable<T>.
  • Adds sync, async, nullable, empty-result, and unsupported-type tests.
File Description
MethodHandler.cs Detects and materializes collection return types.
CollectionReturnTypesTest.cs Tests supported and rejected collection contracts.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI and others added 4 commits October 12, 2026 19:57
Co-authored-by: twogood <189982+twogood@users.noreply.github.com>
Added error handling for method invocation to capture and rethrow inner exceptions.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: David Eriksson <david@activout.se>
Co-authored-by: twogood <189982+twogood@users.noreply.github.com>
@twogood
twogood force-pushed the copilot/support-common-collection-types branch from 9d62bfa to 433a24f Compare October 12, 2026 17:57
@twogood
twogood merged commit 79ad74d into main Oct 12, 2026
6 checks passed
@twogood
twogood deleted the copilot/support-common-collection-types branch October 12, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support common collection return types for multi-row queries

3 participants