问题
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;
回答1:
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.
来源:https://stackoverflow.com/questions/8812153/petapoco-query-with-typed-parameters