EntityFrameworkCore와 함께 PostgreSQL을 사용합니다. jsonb
필드를 일괄 업데이트 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) jsonb
Batch Update
가 json
및 jsonb
유형으로 지원됩니다.