Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
42883:函数不存在-在实体框架C#Npgsql中调用Postgres函数_C#_Postgresql_Function - Fatal编程技术网

42883:函数不存在-在实体框架C#Npgsql中调用Postgres函数

42883:函数不存在-在实体框架C#Npgsql中调用Postgres函数,c#,postgresql,function,C#,Postgresql,Function,我的Postgres数据库中有以下功能 CREATE OR REPLACE FUNCTION "thisSearchList"(IN searchstring text) RETURNS TABLE(q_description text, q_barcode text) AS $BODY$ SELECT q_description, q_barcode FROM q_product WHERE q_description like $1 OR q_barcode li

我的Postgres数据库中有以下功能

CREATE OR REPLACE FUNCTION "thisSearchList"(IN searchstring text)
 RETURNS TABLE(q_description text, q_barcode text) AS
$BODY$
    SELECT q_description, q_barcode 
    FROM q_product
    WHERE q_description like $1
OR q_barcode like $1    
$BODY$
LANGUAGE sql VOLATILE
COST 100
ROWS 1000;
在我的C#代码中,我有以下代码来使用上述函数

NpgsqlConnection connection = new NpgsqlConnection("Host=192.168.0.52;Database=bolo;Username=western;Password=western");
connection.Open(); /*OPEN DATABASE CONNECTION*/

NpgsqlCommand cmd = new NpgsqlCommand("thisSearchList", connection);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@string", NpgsqlTypes.NpgsqlDbType.Text);
cmd.Parameters["@string"].Value = searchValue.ToUpper();

NpgsqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())
{
var prod = new ProductViewModel();
prod.q_description = dr["q_description"].ToString();
prod.q_barcode = dr["q_barcode"].ToString();               

model.Add(prod);  
}
在运行应用程序时,用户在搜索文本框中键入并单击搜索以触发该功能,并返回要显示在视图/页面上的产品列表:我得到以下错误

42883: function thissearchlist(string := text) does not exist
消息来源是

NpgsqlDataReader dr = cmd.ExecuteReader();
从我通过谷歌搜索的理解来看,Postgres可能在字符串和文本方面有问题!?其中,它寻找的函数具有参数字符串,而不是db中定义的文本(只能在postgres中定义文本(而不是字符串))。但是这条线不是吗

cmd.Parameters.Add("@string", NpgsqlTypes.NpgsqlDbType.Text);

在将参数与函数一起传递时会解决这个问题,因此在调用时它会得到相应的函数(带有文本参数)?在这一点上我遗漏了什么,或者用这种方式调用postgres函数是不可能的?

创建函数时使用了双引号和大写字母,因此它的名称现在区分大小写

CREATE OR REPLACE FUNCTION "thisSearchList"
在C#代码中调用函数时,您引用的是一个字符串,但该字符串的内容不包含函数名所需的引号(区分大小写),这就是您收到的错误消息以小写字母显示函数名的原因

new NpgsqlCommand("thisSearchList", connection);
痛苦的方法是添加第二个引号:

new NpgsqlCommand("\"thisSearchList\"", connection);
从长远来看,简单的方法是通过删除引号来消除函数的大小写敏感性:

**编辑**


您正在使用命名参数,但名称不匹配。您应该使用
@searchstring
而不是
@string
,或者根本不使用任何名称来使用位置参数匹配。

我去掉了函数中的qoutes,以小写形式重命名了函数,但仍然会遇到相同的错误。@JHG我已将代码更改为使用searchstring。没有出现错误,我正在进入搜索结果页面,但是它是空的,并且没有显示字符串中的记录,否则该字符串应该包含记录。在这种情况下,返回类型和view/cshtml代码可能是错误的吗?这是另一个问题。。。尽管您缺少与
类似的
关联的
%
。与相同。感谢@JGH一如既往的帮助,我将查看该链接。干杯。使用同一个用户“western”,您能否成功调用plsql控制台/pgadmin中的存储过程?(即western是否拥有该职能的执行权)是的,我可以。“western”是拥有所有权限的超级用户。
CREATE OR REPLACE FUNCTION thisSearchList