C# 使用npgsql将字符串存储为jsonb列

C# 使用npgsql将字符串存储为jsonb列,c#,.net-core,entity-framework-core,jsonb,npgsql,C#,.net Core,Entity Framework Core,Jsonb,Npgsql,我有下面的型号 public class Guardian { public int id { get; set; } public string username { get; set; } public string email { get; set; } public string firstName { get; set; } public string lastName { get; set; }

我有下面的型号

public class Guardian
    {
        public int id { get; set; }
        public string username { get; set; }
        public string email { get; set; }
        public string firstName { get; set; }
        public string lastName { get; set; }
        public string gender { get; set ;}
        public string address { get; set; }

        public string Questions;

        public IList<Urgency> Urgencies { get; set; } = new List<Urgency>();
    }

这完全有道理,但我不知道该怎么做,我做了研究,但似乎没有针对我的具体情况。我非常感谢您的建议。

HasColumnType
-这是一种通用的EF核心方法-接受数据库类型名称是字符串(例如字符串
jsonb
),而不是特定于Npgsql的
NpgsqlDbType.Enum
。您只需按如下方式更改代码:

builder.Entity().Property(d=>d.Questions).HasColumnType(“jsonb”);

有关JSON映射的此信息和其他信息。

HasColumnType
-这是一种通用的EF核心方法-接受数据库类型名称是字符串(例如字符串
jsonb
),而不是Npgsql特定的
NpgsqlDbType.Enum
。您只需按如下方式更改代码:

builder.Entity().Property(d=>d.Questions).HasColumnType(“jsonb”);

有关JSON映射的此信息和其他信息。

快速尝试:根据,应该是
HasColumnType(“jsonb”)
@NateBarbettini非常感谢您快速尝试:根据,应该是
HasColumnType(“jsonb”)
@NateBarbettini非常感谢您
builder.Entity<Guardian>().Property(d => d.Questions).HasColumnType(NpgsqlDbType.Jsonb);
Argument 2: cannot convert from 'NpgsqlTypes.NpgsqlDbType' to 'string'