From fbf207ea07cece4c9df686ada6b80588e8196b5a Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Thu, 3 Nov 2022 12:30:47 +0800 Subject: [PATCH] Fix a bug of entity version updating in `ExternalEntitySynchronizer` --- .../Events/Distributed/ExternalEntitySynchronizer.cs | 5 ++++- .../ExternalEntitySynchronizer_Tests.cs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/Distributed/ExternalEntitySynchronizer.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/Distributed/ExternalEntitySynchronizer.cs index df8806d9d7..27260bcee7 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/Distributed/ExternalEntitySynchronizer.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/Distributed/ExternalEntitySynchronizer.cs @@ -114,8 +114,11 @@ public abstract class ExternalEntitySynchronizer : } else { + // The version will auto-increment by one when the repository updates the entity. + var entityVersion = eto.EntityVersion - 1; + await MapToEntityAsync(eto, localEntity); - ObjectHelper.TrySetProperty(localEntity, x => x.EntityVersion, () => eto.EntityVersion); + ObjectHelper.TrySetProperty(localEntity, x => x.EntityVersion, () => entityVersion); await _repository.UpdateAsync(localEntity, true); } diff --git a/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Entities/Events/Distributed/ExternalEntitySynchronizers/ExternalEntitySynchronizer_Tests.cs b/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Entities/Events/Distributed/ExternalEntitySynchronizers/ExternalEntitySynchronizer_Tests.cs index e0b86c82ea..c32ea0e513 100644 --- a/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Entities/Events/Distributed/ExternalEntitySynchronizers/ExternalEntitySynchronizer_Tests.cs +++ b/framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Entities/Events/Distributed/ExternalEntitySynchronizers/ExternalEntitySynchronizer_Tests.cs @@ -60,7 +60,7 @@ public class ExternalEntitySynchronizer_Tests : AbpIntegratedTest