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?
答案 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。
答案 1 :(得分:0)
试试这个:
var result = c.Query<Xxx>("dbo.xxx_xxxGetPage", new {1}).AsList();