Question

Using PetaPoco, how do i call stored procedure with typed parameters? in c# i do it like this:

cmd.Parameters.Add("@email", SqlDbType.NVarChar).Value = email;
Was it helpful?

Solution

Check out the documentation for further details but here is an extract.

http://www.toptensoftware.com/Articles/114/PetaPoco-What-s-new-in-v4-0

Support for IDbParameters as SQL arguments

PetaPoco now supports directly passing IDbParameter objects to a query. This is handy if PetaPoco doesn't correctly map a property.

For example the SQL Server driver doesn't handle assigning DbNull to a VarBinary column unless the parameter is configured with the correct type. To work around this you can now do this:

databaseQuery.Execute("insert into temp1 (t) values (@0)", new SqlParameter() { SqlDbType = SqlDbType.VarBinary, Value = DbNull.Value });

One interesting side effect of this is that you can also return an IDbParameter from the PetaPoco.IMapper interface to globally override PetaPoco's default parameter mapping functionality.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top