c# - 强制参数,Dapper 和 System.Data.SqlClient.SqlException

标签 c# dapper

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

这是我的代码片段:

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

应该工作但引发异常:

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.

为什么?

最佳答案

我认为您缺少 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

关于c# - 强制参数,Dapper 和 System.Data.SqlClient.SqlException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32965804/

相关文章:

c# - 如何根据已过期的输入文件执行 msbuild (csproj) 目标

c# - 搜索算法 C#

asp.net-web-api - 在 Dapper 中调用 QueryAsync 会抛出 InvalidOperationException

dapper - Dapper 可以实现多个删除插入或更新为 QueryMultiple 吗?

Dapper 多映射两个相同类型的属性

c# - 使用 Dapper 点网映射域实体的私有(private)属性

c# - 为什么 Task<TResult>.Result 在这种情况下不起作用?

c# - 未找到用于绑定(bind)配方的数据上下文

c# - 是否可以使用 Epplus 在 Excel 中复制行(包含数据、合并、样式)?

c# - Dapper .net 多次查询 'The reader has been disposed' 错误