QueryMultiple with CommandType.StoredProcedure fails with exception
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
Hello and thanks for creating Dapper.
I have run in to what I believe is a bug with QueryMultiple and commandType= StoredProcedure:
Given this stored procedure:
CREATE PROCEDURE Test
@Value1 int,
@Value2 int
AS
BEGIN
SET NOCOUNT ON;
SELECT @Value1 AS [Value]
SELECT @Value2 AS [Value]
END
The following code which I expected to work fails with an exception:
"The member Comparer of type System.Collections.Generic.IEqualityComparer`1[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]] cannot be used as a parameter value
var parameters = new Dictionary<string, object>
{
{ "Value1", "1" },
{ "Value2", "2" }
};
using (var connection = new SqlConnection("Data Source=.;Initial Catalog=DapperIssueDemo;Integrated Security=true"))
{
using (var reader = await connection.QueryMultipleAsync(new CommandDefinition("Test", commandType: System.Data.CommandType.StoredProcedure, parameters: parameters)))
{
var values1 = (await reader.ReadAsync<Poco>()).ToList();
var values2 = (await reader.ReadAsync<Poco>()).ToList();
}
}
Here is a workaround that works:
IEnumerable<Poco> Read(IDataReader reader)
{
var parser = reader.GetRowParser<Poco>();
while (reader.Read())
{
yield return parser(reader);
}
}
using (var connection = new SqlConnection("Data Source=.;Initial Catalog=DapperIssueDemo;Integrated Security=true"))
{
using (var reader = await connection.ExecuteReaderAsync(new CommandDefinition("Test", commandType: System.Data.CommandType.StoredProcedure, parameters: parameters)))
{
var values1 = Read(reader).ToList();
var values2 = Read(reader).ToList();
}
}
A working console app demonstrating the issue can be found here: https://atcomsa-my.sharepoint.com/:u:/g/personal/giannis_korres_atcom_gr/ERy9rSHa1gZBvXCXsx_hpcsBrw54d3Zrq9LPEFaNJmvOeQ?e=rm79Em
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
Use the linked console application to reproduce the failure with QueryMultipleAsync and CommandType.StoredProcedure. Start by tracing QueryMultipleAsync and compare it with the working ExecuteReaderAsync path. Done means the stored procedure returns both result sets without the parameter-value exception, while preserving the reported workaround behavior.
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
- 35/100