Unable to pass an empty table-valued parameter through Dapper
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
The following code will throw an exception on 1.50.2.0, with the message "to send a table-valued parameter with no rows, use a null reference for the value instead."
Connection.Execute("TestTVP", new { Table = Enumerable.Empty<SqlDataRecord>() },
transaction: Transaction, commandType: CommandType.StoredProcedure);
Following that advice, I used this code and got this message: "DBNull value for parameter 'Table' is not supported. Table valued parameters cannot be DBNull"
Connection.Execute("TestTVP", new { Table = null as IEnumerable<SqlDataRecord> },
transaction: Transaction, commandType: CommandType.StoredProcedure);
I know this is probably SqlClient's fault, but shouldn't dapper handle this?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two Execute calls from the issue and trace Dapper's table-valued-parameter handling for IEnumerable. Compare the empty enumerable and null cases, then add coverage for the supported behavior and verify that an empty table-valued parameter no longer produces the contradictory exceptions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100