Error while executing a stored procedure that returns no results

I am currently using dapper in one of our projects and we are constantly executing stored procedures. In the first few methods, everything worked fine when the stored procedure we are executing returns strings.

Right now I am facing a problem when I am trying to fetch data from a stored procedure that returns information when it is found. This is a very common use case (for example, registering users in an application). When the method is called Query

and sproc does not return any lines, dapper issues a message ArgumentException

with the message:

"When using mipmap APIs make sure you set the splitOn parameter if you have keys other than Id name parameter: splitOn"

The code I use 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 know there is a method Execute

that should be used when a procedure is expected to return no rows, but that really is not my situation. Also, the dapper exception is misleading since I am not using multi-matching.

Any ideas? Thank!

+3


source to share


1 answer


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



+3


source







All Articles