PetaPoco query with typed parameters

2019-06-27 16:00发布

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;

标签: petapoco
1条回答
何必那么认真
2楼-- · 2019-06-27 16:50

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.

查看更多
登录 后发表回答