强制参数,Dapper 和 System.Data.SqlClient.SqlException
Mandatory parameters, Dapper and System.Data.SqlClient.SqlException
我正在使用 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.
为什么?
试试这个:
var result = c.Query<Xxx>("dbo.xxx_xxxGetPage", new {1}).AsList();
我认为你错过了 CommandType
。
using (var c = _connectionWrapper.DbConnection)
{
var result = c.Query<Xxx>("dbo.xxx_xxxGetPage", new { idProject = 1 }, commandType: CommandType.StoredProcedure).AsList();
return result;
}
默认情况下,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.
为什么?
试试这个:
var result = c.Query<Xxx>("dbo.xxx_xxxGetPage", new {1}).AsList();
我认为你错过了 CommandType
。
using (var c = _connectionWrapper.DbConnection)
{
var result = c.Query<Xxx>("dbo.xxx_xxxGetPage", new { idProject = 1 }, commandType: CommandType.StoredProcedure).AsList();
return result;
}
默认情况下,dapper 使用文本。