Calling stored procedures with parameters in PetaPoco

时光毁灭记忆、已成空白 提交于 2019-12-02 22:25:55
Tech Xie

Update:

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

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.

In my case, I did the following

db.EnableAutoSelect = false;

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

It worked!

As of v6.0.344-beta, PetaPoco now supports stored procedures without needing to use EXEC. See https://github.com/CollaboratingPlatypus/PetaPoco/wiki/Stored-procedures

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!