0

我将 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?

难道我做错了什么?

4

1 回答 1

1

免责声明:我是实体框架扩展的所有者

从 v2.6.2 开始(用于实体框架扩展),json现在jsonb支持类型Batch Update

于 2019-07-03T10:33:19.693 回答