实体框架不保存JSONB属性
我有一个更新方法:
public class User
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string City { get; set; }
[Column(TypeName = "jsonb")]
}
public async Task<bool> Update(int id, UserRequest user)
{
var result = await _context.Users.Where(x => x.Id == id).FirstOrDefaultAsync();
var cities = new List<string>();
cities.Add("New York");
cities.Add("London");
result = new Users()
{
Id = result.Id,
FirstName = user.FirstName,
LastName = user.LastName,
City = JsonSerializer.Serialize(cities)
};
// _context.Entry(result).Property(x => x.City).IsModified = true;
await _context.SaveChangesAsync();
return true;
}
名称和姓氏更改反映在数据库中,但在城市数据库中不反映。
_context.Entry(result).Property(x => x.City).IsModified = true;
作为解决方案,通常使用了输入功能,但是条目
属性为我丢下错误:
计算数据库错误页面内容时发生了例外。
跳过数据库错误页面的显示。
system.invalidoperationException:
由于响应已经启动,因此无法设置状态代码。
I have an update method:
public class User
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string City { get; set; }
[Column(TypeName = "jsonb")]
}
public async Task<bool> Update(int id, UserRequest user)
{
var result = await _context.Users.Where(x => x.Id == id).FirstOrDefaultAsync();
var cities = new List<string>();
cities.Add("New York");
cities.Add("London");
result = new Users()
{
Id = result.Id,
FirstName = user.FirstName,
LastName = user.LastName,
City = JsonSerializer.Serialize(cities)
};
// _context.Entry(result).Property(x => x.City).IsModified = true;
await _context.SaveChangesAsync();
return true;
}
FirstName and LastName change is reflected in db but not in City db.
_context.Entry(result).Property(x => x.City).IsModified = true;
As a solution, generally used the Entry feature, but the Entry
property throws an error for me:
An exception occurred while calculating the database error page content.
Skipping display of the database error page.
System.InvalidOperationException:
StatusCode cannot be set because the response has already started.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白问题的原因,但是以下更改解决了我的问题。
到
I don't understand the cause of the issue but the following change solved my issue.
to