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

时间:2015-10-06 09:01:11

标签: 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?

2 个答案:

答案 0 :(得分:3)

我认为你错过了CommandType

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

默认情况下,dapper使用Text。

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

答案 1 :(得分:0)

试试这个:

var result = c.Query<Xxx>("dbo.xxx_xxxGetPage", new {1}).AsList();