gpt4 book ai didi

带类型参数的 PetaPoco 查询

转载 作者:行者123 更新时间:2023-12-02 22:13:00 25 4
gpt4 key购买 nike

使用 PetaPoco,如何调用带有类型参数的存储过程?在 C# 中我这样做:

cmd.Parameters.Add("@email", SqlDbType.NVarChar).Value = email;

最佳答案

查看 documentation了解更多详细信息,但这里是摘录。

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("插入到 temp1 (t) 值 (@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.

关于带类型参数的 PetaPoco 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8812153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com