EntityFrameworkCoreでPostgreSQLを使用しています。 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)から、 json
およびjsonb
タイプがBatch Update
サポートされるようになりました