abp icon indicating copy to clipboard operation
abp copied to clipboard

An error issue when using both ToJson() and UpdateMany() methods or manually enabled multiple UnitOfWorks

Open choby opened this issue 1 year ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Description

When there is a jsonb field on the data table and it is mapped using ToJson(), and the jsonb field has not been modified. using the UpdateMany() method will result in an error:

System.InvalidOperationException: The value of shadow key property 'ProduceTrackingCuttingRequire.Id' is unknown when attempting to save changes. This is because shadow property values cannot be preserved when the entity is not being tracked. Consider adding the property to the entity's .NET type. See https://aka.ms/efcore-docs-owned-collections for more information.

But when I use the Update() method within a loop, there is no issue.

Reproduction Steps

No response

Expected behavior

No response

Actual behavior

No response

Regression?

No response

Known Workarounds

No response

Version

8.0.5

User Interface

Angular

Database Provider

EF Core (Default)

Tiered or separate authentication server

Tiered

Operation System

Linux

Other information

No response

choby avatar Apr 27 '24 05:04 choby

Applications often make errors after a recent upgrade to.NET 8, I found that if I used tojson() to map jsonb fields, I encountered this problem when I manually enabled multiple UnitOfWorks, and I didn't encounter this problem when I fell back on the tojson() method to HasColumnType("jsonb"). Also note that I made an http request in the UnitOfWork:

Npgsql.NpgsqlException: Exception while writing to stream ---> System.IO.IOException: Unable to write data to the transport connection: Operation canceled. ---> System.Net.Sockets.SocketException: Operation canceled at Npgsql.Internal.NpgsqlWriteBuffer.d__32.MoveNext() at offset 282 --- End of inner exception stack trace --- at Npgsql.Internal.NpgsqlWriteBuffer.d__32.MoveNext() at offset 682 at Npgsql.NpgsqlCommand.<g__WriteExecute|100_0>d.MoveNext() at offset 1709 at Npgsql.NpgsqlCommand.d__119.MoveNext() at offset 1155 at Npgsql.NpgsqlCommand.d__107.MoveNext() at offset 146 at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.d__14.MoveNext() at offset 779 at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.d__17.MoveNext() at offset 279

When this error occurs, the database fails to log the error log most of the time, Occasionally, however, the following errors are recorded: ERROR: SAVEPOINT can only be used in transaction blocks

And this problem seems to exist only in certain scenarios, for example, I run it perfectly in debug mode on my macbook, but I run it 3-4 times out of 10 on ubuntu

pgsql: 14 system: ubuntu 22.04 .net: 8.0 efcore 8.0 efcore.pg:8.0.2 abp:8.0.5

choby avatar Apr 30 '24 02:04 choby

hi

This doesn't seem to be related to abp.

If you can reproduce this problem with some code or a simple project, Please share them,

Thanks.

maliming avatar May 02 '24 07:05 maliming