feat(mapping): MapToSqlTableValuedParameter attribute and empty/struct TVP fixes - #2
Draft
dtraft wants to merge 1 commit into
Draft
feat(mapping): MapToSqlTableValuedParameter attribute and empty/struct TVP fixes#2dtraft wants to merge 1 commit into
dtraft wants to merge 1 commit into
Conversation
This was referenced Sep 8, 2026
Draft
…t TVP fixes > Claude Code (Claude Fable 5.1) Adds MapToSqlTableValuedParameterAttribute mapping a collection property to a table-valued parameter, converting value-type collections such as ImmutableArray<T> to IEnumerable<T> explicitly and normalizing a default ImmutableArray<T> to Empty. Both AddSqlTableValuedParameter overloads now send DBNull for an empty collection instead of an unusable empty record list. Adds read and write tests for the collection mapping.
dtraft
force-pushed
the
collection-mapping
branch
from
September 8, 2026 19:04
8e7a622 to
11a6cbe
Compare
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.
TL;DR
Adds
MapToSqlTableValuedParameterAttributeso a collection property maps to a SQL Server table-valued parameter on write (and, with the shared mapper change, to an additional result set on read), and fixes two TVP edge cases inAddSqlTableValuedParameter.Changes
SqlMapAttributes.cs: newMapToSqlTableValuedParameterAttribute(parameterName, typeName) : CollectionMapAttributeBase. The emitted expression callsAddSqlTableValuedParameter<TElement>and setsSqlParameter.TypeName. Value-type collections (ImmutableArray<T>) are explicitly converted toIEnumerable<T>(Expression.Call requires reference-assignability), and a default (uninitialized)ImmutableArray<T>-- which throws on enumeration -- is normalized toEmpty.SqlParameterCollectionExtensions.cs: bothAddSqlTableValuedParameteroverloads sendDBNull.Valuefor an empty collection (an emptyIEnumerable<SqlDataRecord>cannot supply TDS metadata and is rejected by the driver; SQL Server treats a null TVP as an empty table). ThecolumnListoverload previously had no empty guard at all.test/CollectionMapWriteTests.cs(populated/empty/default collections through both overloads and throughCreateInputParameters, forList<T>andImmutableArray<T>) andtest/CollectionMapReadTests.cs(multi-result-set hydration, declaration order, empty vs missing result set, missing record, attribute-less model,ImmutableArray<T>read).Testing
ArgentSea.Sql.Test: 116 passed, 0 failed (101 pre-existing + 15 new). Exercised live against SQL Server by a downstream Orleans grain whose state carries two TVP-mapped collections.
Dependencies
Depends on argentsea/shared (CollectionMapAttributeBase and the read-side handler). Second of four: shared -> sql -> Orleans -> Orleans.Sql.
Related PRs (merge in this order)