如何解决无法准备NpgsqlCommand?
我当前正在尝试执行准备好的命令,但是由于某种原因我收到了此错误
Hint "There is a column named \"entity_id\" in table \"temp_country\",but it cannot be referenced from this part of the query." string
当我这样做
connection.Execute(@$"DROP TABLE IF EXISTS temp_{entityName}; select * into temp_{entityName} from {entityName}");
var getNewIdSql =
$"INSERT INTO \"temp_{entityName}\"(entity_id) values(@entity_id) RETURNING entity_id";
NpgsqlCommand insertEntry = new NpgsqlCommand(getNewIdSql,connection,transaction);
insertEntry.Prepare();
我不确定在这里我做错了什么吗?因为表存在,并且有列?所以我不确定为什么会出错。
解决方法
错误消息的确令人误解,但问题很简单,您没有在调用Prepare之前将entity_id
的NpgsqlParameter添加到NpgsqlCommand中。
NpgsqlCommand insertEntry = new NpgsqlCommand(getNewIdSql,connection);
var param = new NpgsqlParameter("entity_id",NpgsqlDbType.Integer);
insertEntry.Parameters.Add(param);
insertEntry.Prepare();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。