Browse Source

Fix a bug of entity version updating in `ExternalEntitySynchronizer`

pull/14197/head
gdlcf88 4 years ago
parent
commit
fbf207ea07
  1. 5
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/Distributed/ExternalEntitySynchronizer.cs
  2. 4
      framework/test/Volo.Abp.Ddd.Tests/Volo/Abp/Domain/Entities/Events/Distributed/ExternalEntitySynchronizers/ExternalEntitySynchronizer_Tests.cs

5
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/Distributed/ExternalEntitySynchronizer.cs

@ -114,8 +114,11 @@ public abstract class ExternalEntitySynchronizer<TEntity, TExternalEntityEto> :
} }
else else
{ {
// The version will auto-increment by one when the repository updates the entity.
var entityVersion = eto.EntityVersion - 1;
await MapToEntityAsync(eto, localEntity); await MapToEntityAsync(eto, localEntity);
ObjectHelper.TrySetProperty(localEntity, x => x.EntityVersion, () => eto.EntityVersion); ObjectHelper.TrySetProperty(localEntity, x => x.EntityVersion, () => entityVersion);
await _repository.UpdateAsync(localEntity, true); await _repository.UpdateAsync(localEntity, true);
} }

4
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<ExternalEntity
var book = await repository.FindAsync(bookId); var book = await repository.FindAsync(bookId);
book.ShouldNotBeNull(); book.ShouldNotBeNull();
book.EntityVersion.ShouldBe(remoteBookEto.EntityVersion); book.EntityVersion.ShouldBe(0);
book.Sold.ShouldBe(1); book.Sold.ShouldBe(1);
remoteBookEto.EntityVersion = 1; remoteBookEto.EntityVersion = 1;
@ -70,7 +70,7 @@ public class ExternalEntitySynchronizer_Tests : AbpIntegratedTest<ExternalEntity
book = await repository.FindAsync(bookId); book = await repository.FindAsync(bookId);
book.ShouldNotBeNull(); book.ShouldNotBeNull();
book.EntityVersion.ShouldBe(remoteBookEto.EntityVersion); book.EntityVersion.ShouldBe(1);
book.Sold.ShouldBe(2); book.Sold.ShouldBe(2);
remoteBookEto.EntityVersion = 0; remoteBookEto.EntityVersion = 0;

Loading…
Cancel
Save