2
我已经编写了以下方法来调用我的proc并将返回的数据放入数据集中。用Dapper调用SQL处理程序
public class GetDataFromProc
{
string constr;
public DataSet CallProcToDataSet(string procName)
{
DataSet ds = new DataSet();
constr = ConfigurationManager.ConnectionStrings["DataBase"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(procName))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
sda.Fill(ds);
}
}
}
return ds;
}
我想要做的就是使用Dapper NuGet包。通过文档检查,我可以看到的例子PROC呼叫线路如下:
var user = cnn.Query<User>("spGetUser", new { Id = 1 }, commandType: CommandType.StoredProcedure).SingleOrDefault();
但是,我不知道什么是最好的方式,我的方法转化成以上的例子可以。有更多Dapper经验的人能帮助我吗?