【发布时间】:2021-12-03 16:22:36
【问题描述】:
public Class Employee{
public string Name { get; set; }
[Column(TypeName = "jsonb")]
public List<Section> Sections { get; set; }
}
public Class Sections{
public string Booking { get; set; }
[Column(TypeName = "jsonb")]
public List<Interest> Interests { get; set; }
}
public Class Interest{
public string Title { get; set; }
public List<Meta> Meta { get; set; }
public List<WithAlt> Images { get; set; }
}
public Class Meta{
public string Type { get; set; }
public string Content { get; set; }
}
public Class WithAlt{
public string content { get; set; }
public string Alt { get; set; }
}
我从 Employee 表中获取数据
员工在获取数据时 Sections Column 我得到了
The JSON value could not be converted to System.String. Path: $[1].Interests[1].Meta[9].Content | LineNumber: 0 | BytePositionInLine: 10073.
发生错误
public Task<Employee> CheckEmployee(string name){
// error throw Line
var query= await catalogDbContext.Employee
.Where(i.Name === name)
.FirstOrDefault();
}
并非所有价值,而是List<Section> 或
List<Interest> 或 List<Meta> 或 List<WithAlt> 具有空值
当我手动将值添加到下面的部分列时
{
"Booking": "",
"Interests":[
{
"Title":"",
"Meta":[
{
"Type" : " ",
"Content" : " "
}
],
"Images" : [
{
"content" : " ",
"alt" : " "
}
]
}
],
}
不会报错
有没有办法使用代码优先的方法为上述字段定义默认值
当我初始化 Sections 属性时
public List<Section> Sections { get; set; }={};
它显示以下错误
Can only use array initializer expressions to assign to array types. Try using a new expression instead.
还有
public List<Section> Sections { get; set; }= new List<Section> Sections();
和
public List<Meta> Meta { get; set; }= = new List<Meta>();
和
public List<WithAlt> Images { get; set; }= new List<WithAlt>();
投掷Error "The JSON value could not be converted to System.String. Path: $[1].Interests[1].Meta[9].Content | LineNumber: 0 | BytePositionInLine: 10073."
【问题讨论】:
-
请问可以发原始的json吗?
-
{“预订”:“”,“兴趣”:[{“标题”:“”,“元”:[{“类型”:“”,“内容”:“”}] , "图片" : [ { "content" : " ", "alt" : " " } ] } ], }
标签: postgresql entity-framework asp.net-core c#-4.0 entity-framework-6