【问题标题】:How can I batch update jsonb field using Entity Framework Extensions library?如何使用实体框架扩展库批量更新 jsonb 字段?
【发布时间】:2019-11-08 19:46:17
【问题描述】:

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

我做错了吗?

【问题讨论】:

    标签: postgresql entity-framework-core jsonb entity-framework-plus entity-framework-extensions


    【解决方案1】:

    免责声明:我是Entity Framework Extensions的所有者

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-07
      • 2018-12-03
      • 2014-07-12
      • 2012-07-11
      • 2017-03-01
      • 1970-01-01
      相关资源
      最近更新 更多