使用PetaPoco中的参数调用存储过程

时间:2021-05-24 11:01:31

I want to be able to call a stored proc with named parameters in PetaPoco.

我希望能够在PetaPoco中调用带有命名参数的存储过程。

In order to call a stored proc that does a search/fetch:

为了调用执行搜索/获取的存储过程:

Can I do something like this:

我可以这样做:

return db.Fetch<Customer>("EXEC SP_FindCust",
new SqlParameter("@first_name", fName),
new SqlParameter("@last_name", lName),
new SqlParameter("@dob", dob));

Also, how can I call a stored proc that does an insert?

另外,如何调用执行插入的存储过程?

return db.Execute("EXEC InsertCust @CustID = 1, @CustName = AAA")

Thanks, Nac

谢谢,Nac

1 个解决方案

#1


26  

Update:

更新:

I tried the following for fetch and insert and it worked perfectly:

我尝试了以下fetch和insert,它完美地工作:

var s = PetaPoco.Sql.Builder.Append("EXEC SP_FindCust @@last_name = @0", lname);
s.Append(", @@first_name = @0", fName);
s.Append(", @@last_name = @0", lName);
s.Append(", @@dob = @0", dob);
return db.Query<Cust>(s);

This can be improved further to pass SQL parameters.

这可以进一步改进以传递SQL参数。

#1


26  

Update:

更新:

I tried the following for fetch and insert and it worked perfectly:

我尝试了以下fetch和insert,它完美地工作:

var s = PetaPoco.Sql.Builder.Append("EXEC SP_FindCust @@last_name = @0", lname);
s.Append(", @@first_name = @0", fName);
s.Append(", @@last_name = @0", lName);
s.Append(", @@dob = @0", dob);
return db.Query<Cust>(s);

This can be improved further to pass SQL parameters.

这可以进一步改进以传递SQL参数。