我有以下型号
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>();
}
以及我的AppDbContext上的这一行代码:DbContext
builder.Entity<Guardian>().Property(d => d.Questions).HasColumnType(NpgsqlDbType.Jsonb);
我希望将Questions字符串字段存储为PostgreSQL数据库上的JsonB类型。我收到此错误:
Argument 2: cannot convert from 'NpgsqlTypes.NpgsqlDbType' to 'string'
这完全有道理,但不知道我该如何处理,我已经进行了研究,但似乎没有针对我的特定情况的。我真的很感谢一些建议。
基于Postgre documentation中的信息,可能是编码问题。我不知道您的数据库配置,但是对您来说可能是个好主意。
如果您的JSON以字符串的形式进入程序(.NET字符串编码为UNICODE / UTF-16),并且将它们解析为另一种格式,这可能会导致丢失信息或生成与UNICODE / UTF不兼容的字符-16编码。