DapperLib / DapperLib/Dapper

System.ArgumentException is thrown when passing empty SqlDataRecord list as an anonymous object or as table-valued parameter to Dapper.

Open
#901 0 comments 0 reactions 0 assignees View on GitHub

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 exception is thrown when I try to execute stored procedure through Dapper and passing
SqlDataRecordListTVPParameter implementation of the interface ICustomQueryParameter. The code looks like this :

Proposed fix which worked for me : https://github.com/StackExchange/Dapper/pull/900/files

CommandDefinition commandDefinition = 
new CommandDefinition(
   query, 
   new DynamicParameters(new IEnumerable<SqlDataRecord>(){ }).AsTableValuedParameter(), 
   null, 
   null, 
   CommandType.StoredProcedure);

var result= connection.Query<int>(commandDefinition ).ToList();

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the SqlDataRecordListTVPParameter implementation of ICustomQueryParameter and compare the proposed fix in PR 900; reproduce the empty IEnumerable call shown in the issue. Done means executing the stored procedure with an empty table-valued parameter no longer throws System.ArgumentException.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.