Npgsql 按名称将参数传递给存储函数

发布于 2024-08-24 15:47:34 字数 400 浏览 4 评论 0原文

我正在使用正在转换为与 .NET 一起使用的 Pgsql 的代码。我想调用一个具有多个参数的存储函数,但我想按名称绑定参数,如下所示:

NpgsqlCommand command = new NpgsqlCommand("\"StoredFunction\"", _Connection)
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("param2", value2);
command.PArameters.Add("param1", value1);

到目前为止尝试执行此操作,查找参数类型与我添加参数的顺序匹配的函数到集合,而不是名字。

Npgsql 是否可以通过名称将参数绑定到存储函数?

I'm working with code I'm converting to Pgsql working with .NET. I want to call a stored function that has several parameters, but I'd like to bind the parameters by name, like so:

NpgsqlCommand command = new NpgsqlCommand("\"StoredFunction\"", _Connection)
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("param2", value2);
command.PArameters.Add("param1", value1);

Attempts to do this so far look for a function with parameter types matching in the order in which I added the parameters to the collection, not by name.

Is it possible for Npgsql to bind parameters to stored functions by name?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

装迷糊 2024-08-31 15:47:34

目前 Npgsql 不支持按名称传递参数。尽管它支持按名称接收参数值。

您介意填写一份有关该问题的错误报告吗?这样我们就可以跟踪并实施它。

Currently Npgsql doesn't support pass parameters by name. Although it supports receiving out parameter values by name.

Would you mind to fill a bug report about that? So we can track and implement it.

禾厶谷欠 2024-08-31 15:47:34

不幸的是,它不适用于存储过程(CommandType.StoredProcedure)。

它使用 SQL 文本命令 (CommandType.Text)。
您可以使用 :paramname,另外我认为在最新版本中您可以使用parameters.addwithvalue(":paramname", param)。

您还可以将 @paramname 与最新版本一起使用(例如 MS Sql Server)。

阅读本手册的“在查询中使用参数”部分,了解回答你原来的问题 - 但请记住我上面所说的,以使你的生活更轻松。

Unfortunately it does not work with store procedure (CommandType.StoredProcedure).

It does with SQL-text command (CommandType.Text).
You can use :paramname, plus I think in the latest version you can use parameters.addwithvalue(":paramname", param).

You can also use @paramname with the latest version (like MS Sql Server).

Read section "Using parameters in a query " of this manual for an answer to your original question - but remember what I said above to make your life easier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文