DapperLib / DapperLib/Dapper

Cell value not converted when using QueryAsync<T> with CommandFlags.None

Open
#1,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

I am using the QueryAsync<T> method with CommandFlags.None so it will not be buffered.

CommandDefinition command = new CommandDefinition("SELECT 1", flags: CommandFlags.None);
IEnumerable<bool> results = await connection.QueryAsync<bool>(command);
foreach (bool result in results)
{
}

Since I am not using a CAST statement, the type returned from the reader does not match the expected result type.
This leads to the following exception, which is reasonable:

System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.Boolean'.
   at Dapper.SqlMapper.ExecuteReaderSync[T](IDataReader reader, Func`2 func, Object parameters)+MoveNext() in /_/Dapper/SqlMapper.Async.cs:line 976
   at ConsoleApp6.Program.Main(String[] args) in \ConsoleApp6\Program.cs:line 14
   at ConsoleApp6.Program.<Main>(String[] args)

However, in such cases, the value is usually converted automatically. I believe this is done by the GetValue method.
This works for the non-async Query method (with either buffered or non-buffered). And also for the async QueryAsync method using CommandFlags.Buffered.
But apparently the GetValue<T> method is not called with the async non-buffered combination.

Is this by design or am I missing something here?

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 in Dapper/SqlMapper.Async.cs at ExecuteReaderSync and the referenced GetValue method, then compare buffered and non-buffered QueryAsync paths. Reproduce the SELECT 1 example with CommandFlags.None and verify that the non-buffered path handles the Int32-to-Boolean result consistently with the other query paths.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.