Repository navigation
Support common collection return types for multi-row queries - #68
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
There was a problem hiding this comment.
🟡 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.
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>
9d62bfa to
433a24f
Compare

MethodHandleronly treated an exactIEnumerable<T>return as a multi-row query. Methods returningIReadOnlyList<T>,List<T>,T[]and similar were handled as single-row results, so callers had to returnIEnumerable<T>and call.ToList()themselves.Changes (
Implementation/MethodHandler.cs)Task<T>payload, is multi-row if it is one ofIEnumerable<T>,IReadOnlyCollection<T>,IReadOnlyList<T>,ICollection<T>,IList<T>,List<T>or a single-dimensionT[]. This is a match on the generic type definition, not on assignability. That keepsstringand user types that merely implementIEnumerable<T>as single values.IEnumerable<object>. The result is cast toT.IEnumerable<T>stays lazy. Everything else is copied into aList<T>, or into an array forT[].System.Collections.*that implementIEnumerable<>, such asHashSet<T>andDictionary<,>, now throwNotSupportedExceptionwhen the DAO is built. The message lists the supported types. The repo has no configuration-exception type, so I reusedNotSupportedException, whichDatabaseClientalready 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.Enumerable.Cast, so they behave as before. SQLite returns integers aslong, soList<int>overSELECT idthrowsInvalidCastException. The new tests useList<long>.CollectionReturnTypesTest.cscovers each supported type in sync and async form, empty and non-empty result sets, nullable elements, and rejection ofHashSet<T>.