Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mandatory parameters, Dapper and System.Data.SqlClient.SqlException

Tags:

c#

dapper

I am using Dapper to call a stored procedure which have a mandatory parameter @idProject

this is my code fragment:

using (var c = _connectionWrapper.DbConnection)
      {
        var result = c.Query<Xxx>("dbo.xxx_xxxGetPage", new { @idProject = 1 }).AsList();
        return result;
      }

Should work but raise an exception:

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: Procedure or function 'xxxGetPage' expects parameter '@idProject', which was not supplied.

Why?

like image 992
alessandro Avatar asked Oct 19 '22 01:10

alessandro


1 Answers

I think you're missing the CommandType.

using (var c = _connectionWrapper.DbConnection)
{
    var result = c.Query<Xxx>("dbo.xxx_xxxGetPage", new { idProject = 1 }, commandType: CommandType.StoredProcedure).AsList();
    return result;
}

By default, dapper uses Text.

https://github.com/StackExchange/dapper-dot-net

like image 120
Phil Cooper Avatar answered Nov 15 '22 04:11

Phil Cooper