How can I batch update jsonb field using Entity Framework Extensions library?

entity-framework-core entity-framework-extensions entity-framework-plus jsonb postgresql


I use PostgreSQL with EntityFrameworkCore. I need to batch update jsonb field. The Z.EntityFramework packages look promising however none of them work for me.

I setup jsonb field with EntityTypeBuilder:

builder.Property(o => o.Description).HasColumnType(NpgsqlDbType.Jsonb);

and with ColumnAttribute:

[Column(TypeName = "jsonb")]
public string Description {get; set;}

It works well with a regular update practice. However when I am trying to batch update field using next packages:

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

Using next code:

.Where(o => o.PropertyId == scope.PropertyId)
.UpdateFromQuery(o => //for EF-Plus a method Update()
    new AgeBucket
        Description = serializedDescription //jsonb

None of them work for me. I receive next exceptions: For EF-Plus:

Npgsql.PostgresException : 42804: column "Description" is of type jsonb but expression is of type text

For EF-Classic and EF-Extensions:

System.Exception : Could not find the context from the IQueryable expression. Are you sure this is coming from an Entity Framework Context?

Am I doing something wrong?

7/3/2019 8:27:47 AM

Accepted Answer

Disclaimer: I'm the owner of Entity Framework Extensions

Starting from v2.6.2 (for Entity Framework Extensions), json and jsonb type are now supported for Batch Update

7/3/2019 10:33:19 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow