Unbuffered QueryAsnyc multi-mapping throws an InvalidOperationException
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
using (var conn = new SqlConnection(appToken.ConnectionString))
{
conn.Open();
var ret = conn.Query("select a='dog',b=3", (string a, int b) => a + b, splitOn: "b", buffered: false);
Console.WriteLine(string.Join("", ret));
ret = conn.QueryAsync("select a='dog',b=3", (string a, int b) => a + b, splitOn: "b", buffered: false).Result;
Console.WriteLine(string.Join("", ret));
}
The call to Query returns dog3, the QueryAsync throws the following exception:
System.InvalidOperationException was unhandled
HResult=-2146233079
Message=Invalid attempt to call FieldCount when reader is closed.
Source=System.Data
StackTrace:
at System.Data.SqlClient.SqlDataReader.get_FieldCount()
at Dapper.SqlMapper.GetColumnHash(IDataReader reader, Int32 startBound, Int32 length)
at Dapper.SqlMapper.<MultiMapImpl>d__140`8.MoveNext()
at System.String.Join(String separator, IEnumerable`1 values)
at Program.Main(String[] args) in
The store procedure I am calling takes a while to execute and I'd rather let it be called async before I start streaming data out of the query.
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 with the Query and QueryAsync entry points and reproduce the shown multi-mapping call against the SQL query with buffered set to false. Compare the synchronous and asynchronous enumeration paths and verify that the reader remains usable while results are streamed. Done means QueryAsync produces dog3 without the closed-reader InvalidOperationException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100