我有以下SP来电
public IEnumerable<classfile> GetData(bool isactive)
{
using (SqlConnection cnn = this.OpenConnection())
{
IList<classfile> SampleList = SqlMapper.Query<classfile>(cnn, "SPName").ToList();
cnn.Close();
return SampleList.ToList();
}
}
如何发送参数以及上面的dapper SP调用
我试过了
public IEnumerable<classfile> GetData(bool isactive)
{
using (SqlConnection cnn = this.OpenConnection())
{
var parameters = new DynamicParameters();
parameters.Add("@isActive", isactive);
IList<classfile> SampleList = SqlMapper.Query<classfile>(cnn, "SPName", parameters).ToList();
cnn.Close();
return SampleList.ToList();
}
}
但是其运行时间会出现以下错误
程序或功能&#39; SPName&#39;期望参数&#39; @ isActive&#39;,哪个 没有提供。
答案 0 :(得分:0)
自己找到答案
public IEnumerable<classfile> GetData(bool isactive)
{
using (SqlConnection cnn = this.OpenConnection())
{
DynamicParameters parameters = new DynamicParameters();
parameters.Add("@isActive", isactive);
IList<classfile> SampleList = SqlMapper.Query<classfile>(cnn, "SPName", parameters, commandType: CommandType.StoredProcedure).ToList();
cnn.Close();
return SampleList.ToList();
}
}
答案 1 :(得分:0)
或者你可以写这样的东西
IList<classfile> SampleList = SqlMapper.Query<classfile>(cnn, "SPName", new
{
isActive = isactive
}
, commandType: CommandType.StoredProcedure).ToList();