【问题标题】:Mandatory parameters, Dapper and System.Data.SqlClient.SqlException强制参数,Dapper 和 System.Data.SqlClient.SqlException
【发布时间】:2015-10-06 09:01:10
【问题描述】:

我正在使用Dapper 调用具有强制参数@idProject 的存储过程

这是我的代码片段:

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

应该可以工作,但会引发异常:

“System.Data.SqlClient.SqlException”类型的异常发生在 System.Data.dll 但未在用户代码中处理

附加信息:过程或函数'xxxGetPage' 需要未提供的参数“@idProject”。

为什么?

【问题讨论】:

  • 删除@ 看看是否有效。

标签: c# dapper


【解决方案1】:

我认为你错过了CommandType

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

默认情况下,dapper 使用文本。

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

【讨论】:

    【解决方案2】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-11
      • 2016-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多