Search code examples
table-valued-parameterspetapoco

Can I pass table valued parameters to a stored procedure with PetaPoco?


I'm trying to use PetaPoco for a project that has some stored procedures. Most of them work fine, however, we have a couple where the stored procedure is expecting an IntList which is a User-Defined Table Type.

I haven't found a way to do this, and I hope I'm just missing something obvious. The current work around that I have is to copy the stored procedure code from SQL into a string and then execute that against my PetaPoco database:

public IEnumerable<UserComments> GetComments(IEnumerable<int> userIds)
{
   using(var db = new Database(connection))
   {
      db.Fetch<UserComments>(new Sql("select UserId, Comment from Comments where UserId in    (@0)", userIds);
   }
}

Solution

  • You can pass a SqlParameter directly in. eg

    db.Fetch<User>("EXECUTE getUser @0", new SqlParameter(,,,,));
    

    So you should be able to call it like you would directly through ADO.net.