DapperLib / DapperLib/Dapper

QueryAsync, non-buffered, with mapping throws "No columns were selected"

Open
#1,418 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-info
Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

This works as expected

await connection.QueryAsync<T1, T2, T1>(
    new CommandDefinition(sql), 
       (t1, t2) => // some mapping func
);

But this throws "No columns were selected" when enumerating the results:

await connection.QueryAsync<T1, T2, T1>(
    new CommandDefinition(sql, flags: CommandFlags.None),  // effectively turning buffering off
       (t1, t2) => // some mapping func 
);

The sync version works both buffered and non-buffered:

connection.Query<T1, T2, T1>(
    sql,
    (t1, t2) => // some mapping func,
    buffered: false
);

Note that the connection is NOT closed at enumeration time.

Tested using Dapper v. 2.0.30 on Postgres database using NpgSql v. 3.2.7.
Upgrading to NpgSql v. 4.1.3.1 still throws an exception, but message is now "The reader is closed"

The QueryAync<T> version (no mapping func) also works as expected non-buffered. We ran into the issue as we needed to add a join and a mapping function to existing code.

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 by reproducing the async multi-mapping case with CommandFlags.None against PostgreSQL, then compare its enumeration with buffered and synchronous Query behavior. The fix is complete when mapped rows enumerate successfully without a "No columns were selected" or reader-closed exception while the connection remains open.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, postgresql
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.