gpt4 book ai didi

c# - 没有字母参数的 Postgresql 的 Dapper 存储过程

转载 作者:行者123 更新时间:2023-11-29 13:35:56 26 4
gpt4 key购买 nike

我正在尝试使用 C# 和 Dapper 调用用 plpgsql 编写的 Postgresql 存储过程,但我发现 Dapper 在将参数插入存储过程之前按字母顺序排列。有什么方法可以避免这种行为并以正确的顺序插入项目?

例如,以下调用将无法正确运行,因为它会将参数名称按字母顺序排列。我必须手动按字母顺序排列它们才能接通电话。

int map_id = conn.Query<int>(
"insert_color",
new
{
zebra_name = new DbString { Value = slide_name },
door_name = new DbString { Value = fov_name },
foo_number = cycle_number,
variable_path = new DbString { Value = image_path },
random_path = new DbString { Value = meta_path },
x = x,
y = y,
z = z,
exposure = exposure,
type_name = new DbString { Value = image_type },
copy = copy
},
commandType: CommandType.StoredProcedure).First();

这是存储过程声明:

CREATE OR REPLACE FUNCTION insert_color(
zebra_name text, door_name text, foo_number integer,
variable_path text, random_path text,
x real, y real, z real, exposure real,
type_nametext, copy integer) RETURNS integer AS $$
...
$$ LANGUAGE plpgsql;

最佳答案

在内部,Dapper 使用反射来获取 param 对象的属性。具体来说,GetProperies(...) 的问题是,不能保证它们按特定顺序排列...

The GetProperties method does not return properties in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which properties are returned, because that order varies.

为了有点用处,他们选择按字母顺序排列参数,但不幸的是,没有办法确保参数按照您在类中的顺序出现。

关于c# - 没有字母参数的 Postgresql 的 Dapper 存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11745709/

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