PetaPoco query with typed parameters

左心房为你撑大大i 提交于 2019-12-23 11:58:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!