DapperLib / DapperLib/Dapper

QueryAsync throws if stored procedure selects no column

Open
#908 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 experiencing an issue where connection.QueryAsync("SP_Test") throws an error when my SP_Test looks like this:

IF NOT EXISTS (@Id = @RetrievedId)
BEGIN
    RETURN 3; -- Not allowed
END

SELECT
      [Id]
    , [Name]
FROM
    Users

RETURN 1; -- Successful

This is what my whole C# code looks like:

var parameters = new DynamicParameters();
parameters.Add("@Id", id);
parameters.Add("@RetVal", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);

var dbResult = await connection.ExecuteAsync("SP_Test", param: parameters, commandType: CommandType.StoredProcedure);

// See if not allowed.
if (parameters.Get<int>("@RetVal") == 3)
{
    return "not allowed";
}
if (parameters.Get<int>("@RetVal") == 1)
{
    return "this is ok";
}
            
//...

There is no problem at all when my SP returns no data (with column selection) or using connection.Query instead but when I don't select anything and return instead, QueryAsync just throws. No matter if I use strongly-typed or anonymous.

Should not dbResult have been null instead?

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

Reproduce the SP_Test stored procedure with QueryAsync, ExecuteAsync, and Query, using the shown return-value parameters. Start at the QueryAsync entry point and trace how a stored procedure result with no selected columns is handled; done means the no-column case has defined, non-throwing behavior consistent with the intended result.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.