如何为Npgsql提供自定义数据类型作为参数? [英] How to provide Npgsql with a custom data type as a parameter?
问题描述
我想使用Npgsql将键值对数组作为参数传递给PostgreSQL函数。我定义了以下类型:
I want to pass an array of key-value pairs as an argument to a PostgreSQL function using Npgsql. I have the following type defined:
drop type if exists key_value_pair
create type key_value_pair as (
k varchar(250),
v text
);
我想编写如下函数:
create or replace function persist_profile(
_user_id integer,
_key_value_pairs key_value_pair[]
) returns boolean as $$
begin;
...
return true;
end;
$$ language plpgsql;
如何从 IDictionary< string,string>传递数据
How would I pass data from a IDictionary<string, string>
object to the stored procedure using Npgsql? Is this supported? I cannot find a reference online.
谢谢!
推荐答案
杰里米!
不幸的是,Npgsql还不支持自定义数据类型。我打算为此添加支持。
Unfortunately, Npgsql doesn't support custom datatypes yet. I have intention to add support for that.
这意味着要使用Npgsql添加某种类型的类型转换器注册。这样,您的应用程序将为您的自定义类型注册一个转换器,而Npgsql将使用它来回发送数据。
This would mean to add some type of "registering" of types converters with Npgsql. This way your application would register a converter for your custom type and Npgsql would use it to send data back and forth.
更多详细信息,请访问:Npgsql / src / cvs.npgsql.org上的NpgsqlTypes / NpgsqlTypeConverters.cs
More details can be get in: Npgsql/src/NpgsqlTypes/NpgsqlTypeConverters.cs on cvs.npgsql.org
请在我们的项目站点project.npgsql.org中添加与此相关的功能请求。
Please, add a feature request about that in our project site: project.npgsql.org.
谢谢。
这篇关于如何为Npgsql提供自定义数据类型作为参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!