Jsonb 函数通过 pgAdmin 工作,但不能通过 C# 中的 Npgsql 工作

Jsonb function works through pgAdmin but won't work through Npgsql in C#

我需要在我的 table 之一的 jsonb 字段中进行更新,我可以通过以下命令成功完成:

update tab set draft = jsonb_set(draft, '{ result }', jsonb '"yes"', true) WHERE id=...

将 jsonb 列更新为 {"result": "yes"}。

当我尝试在 C# 中调用以下代码时,没有错误,但行没有更新。

string query = "update tab set  draft=jsonb_set(draft, '{ result }', jsonb '\"yes\"', true) WHERE id=@uid;";
using (var cmd = new NpgsqlCommand(query, pgsqlConnection))
{
      cmd.Parameters.AddWithValue("uid", 1);
      var ret = cmd.ExecuteNonQuery();  
}

我非常感谢任何关于为什么无法更新 table 的见解。

Npgsql 版本为 v6.0.0

使用前必须配置Json.NET类型插件,如下所示:

using Npgsql;

// Place this at the beginning of your program to use Json.NET everywhere (recommended)
NpgsqlConnection.GlobalTypeMapper.UseJsonNet();

// Or to temporarily use JsonNet on a single connection only:
conn.TypeMapper.UseJsonNet();

有关详细信息,请参阅 https://www.npgsql.org/doc/types/jsonnet.html