Calling stored procedures with parameters in PetaPoco

前端 未结 3 1233
难免孤独
难免孤独 2021-02-04 01:59

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

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

Can I do something like this

相关标签:
3条回答
  • 2021-02-04 02:17

    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

    0 讨论(0)
  • 2021-02-04 02:35

    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.

    0 讨论(0)
  • 2021-02-04 02:35

    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!

    0 讨论(0)
提交回复
热议问题