我將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?
難道我做錯了什麼?
免責聲明 :我是Entity Framework Extensions的所有者
從v2.6.2(對於Entity Framework Extensions)開始, Batch Update
現在支持json
和jsonb
類型