我将PostgreSQL与EntityFrameworkCore一起使用。我需要批量更新jsonb
字段。 Z.EntityFramework软件包看起来很有希望,但是它们都不适合我。
我使用EntityTypeBuilder设置jsonb字段:
builder.Property(o => o.Description).HasColumnType(NpgsqlDbType.Jsonb);
并具有ColumnAttribute:
[Column(TypeName = "jsonb")]
public string Description {get; set;}
它与常规更新实践很好地配合。但是,当我尝试使用下一个软件包批量更新字段时:
Install-Package Z.EntityFramework.Extensions.EFCore -Version 2.6.0
Install-Package Z.EntityFramework.Plus.EFCore -Version 2.0.2
Install-Package Z.EntityFramework.Classic -Version 7.1.9
使用下一个代码:
dbContext.AgeBuckets
.Where(o => o.PropertyId == scope.PropertyId)
.UpdateFromQuery(o => //for EF-Plus a method Update()
new AgeBucket
{
Description = serializedDescription //jsonb
});
他们都不为我工作。我收到下一个例外: 对于EF-Plus:
Npgsql.PostgresException : 42804: column "Description" is of type jsonb but expression is of type text
对于EF-Classic和EF-Extensions:
System.Exception : Could not find the context from the IQueryable expression. Are you sure this is coming from an Entity Framework Context?
我做错什么了吗?
答案 0 :(得分:1)
免责声明:我是Entity Framework Extensions
的所有者从v2.6.2(用于Entity Framework Extensions)开始,json
现在支持jsonb
和Batch Update
类型