我正在使用 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 使用文本。
关于c# - 强制参数,Dapper 和 System.Data.SqlClient.SqlException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32965804/