使用Daper.Net和NPGSQL将数据插入PostgreSQL jsonb列 [英] Inserting data into PostgreSQL jsonb column with Daper.Net and NPGSQL

查看:551
本文介绍了使用Daper.Net和NPGSQL将数据插入PostgreSQL jsonb列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Dapper.Net将JSON数据插入JSONB PostgreSQL列中。

I'm trying to insert JSON data into a JSONB PostgreSQL column using Dapper.Net.

NPGSQL JSONB文档给出了使用 NpgsqlDbType.Jsonb 的具体说明。数据类型。

The NPGSQL Documentation for JSONB gives specific instructions to use the NpgsqlDbType.Jsonb datatype.

使用Dapper,我试图将其添加为自定义参数,但没有成功。

With Dapper, I'm trying to add this as a custom parameter without success.

using (var conn = myconnection)
{
    var sql = "INSERT INTO mytable (jsonbody) VALUES (@jb);";
    dp =  new DynamicParameters();
    dp.Add("jb", stringOfJsonData, (DbType)NpgsqlDbType.Jsonb);
    await conn.ExecuteAsync(sql,dp);                    
}                

我收到的错误是
System.NotSupportedException:PostgreSQL或Npgsql不支持参数类型DbType.36

关于如何使用这两个库的任何建议

Any suggestions on how to use these two libraries together for JSONB?

谢谢。

推荐答案

NpgsqlDbType和DbType是两个不同的枚举,您不能简单地将一个枚举转换为另一个枚举...

NpgsqlDbType and DbType are two different enums, you can't simply cast one into the other...

您必须在其创建并发送的NpgsqlParameters上设置NpgsqlDbType属性。 IIRC有一种指定自定义参数的方法。

You'll have to make for set the NpgsqlDbType property on the NpgsqlParameters it creates and send. IIRC there's a way to specify custom parameters.

这篇关于使用Daper.Net和NPGSQL将数据插入PostgreSQL jsonb列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆