No columns were selected" when there is no result returned by a query in when using QueryMultiple
Open
@mgravell is already working on this.
Since Dec 31, 2023.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
I am using .net core 3.1 with dapper 2.0.35
I am getting error "No columns were selected" when using QueryMultiple
My code looks like following
public static List<List<dynamic>> GetEntityObjectFromClientId(string clientId, int? entityId)
{
List<List<dynamic>> lst = null;
var _params = new DynamicParameters();
_params.Add("@_client_id", clientId, DbType.String, direction: ParameterDirection.Input);
_params.Add("@_entity_id", entityId, DbType.Int32, direction: ParameterDirection.Input);
using (var db = new MySqlConnection(ConnectionString))
{
var resultSet = db.QueryMultiple(StoredProceduresName.mysqp, _params, commandType: CommandType.StoredProcedure);
if (resultSet != null && HasRows(resultSet))//just added HasRows hack
{
var result1 = resultSet.Read();
if (result1 != null && result1.AsList().Count > 0)
{
lst = new List<List<dynamic>>();
lst.Add(result1.AsList());
lst.Add(resultSet.Read().AsList());
lst.Add(resultSet.Read().AsList());
}
}
}
return lst;
}
I have found a hack
private static bool HasRows(SqlMapper.GridReader reader)//https://github.com/StackExchange/Dapper/issues/327
{
MySqlDataReader internalReader = (MySqlDataReader)typeof(SqlMapper.GridReader).
GetField
("reader",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
.GetValue(reader);
return internalReader.HasRows;
}
Ideally HasRows method should be built into dapper
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.
Assessment
This issue has not been assessed yet.