abpframework / abp

Open Source Web Application Framework for ASP.NET Core. Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET and the ASP.NET Core platforms. Provides the fundamental infrastructure, production-ready startup templates, application modules, UI themes, tooling, guides and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.31k stars 3.32k forks source link

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

Open choby opened 3 weeks ago

choby commented 3 weeks ago

Is there an existing issue for this?

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 commented 2 weeks ago

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.d32.MoveNext() at offset 282 --- End of inner exception stack trace --- at Npgsql.Internal.NpgsqlWriteBuffer.d32.MoveNext() at offset 682 at Npgsql.NpgsqlCommand.<g__WriteExecute|100_0>d.MoveNext() at offset 1709 at Npgsql.NpgsqlCommand.d119.MoveNext() at offset 1155 at Npgsql.NpgsqlCommand.d107.MoveNext() at offset 146 at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.d14.MoveNext() at offset 779 at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.d17.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

maliming commented 2 weeks ago

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.