Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error thrown when executing a stored procedure that returns no results

I am currently using dapper on one of our projects and we execute stored procedures all the time. In the first few methods everything was working fine when the stored procedure we execute returns rows.

Right now I'm facing an issue when I try to fetch data from an stored procedure that returns info when found. This is a very common use case (eg. logging users on the application). When calling the Query method, and the sproc does not return any row, dapper throws an ArgumentException with the message:

"When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id Parameter name: splitOn"

The code I'm using is:

using (var conn = new SqlConnection(connString))
{
    conn.Open();

    return conn.Query<Customer>(
            sql: "prc_GetCustomer",
            param: new { Parameter = p },
            commandType: CommandType.StoredProcedure).FirstOrDefault();
}

I'm aware that there is a Execute method that should be used when the procedure is expected to not return any rows but it's really not my situation. Also, dapper exception is misleading, since I'm not using multi-mapping.

Any ideas? Thanks!

like image 545
rocco Avatar asked Jan 18 '13 19:01

rocco


1 Answers

If the query does not return any result grids, you should use Execute, not Query.

like image 64
Marc Gravell Avatar answered Sep 21 '22 15:09

Marc Gravell