diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/ChangeTrackers/AbpEfCoreNavigationHelper.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/ChangeTrackers/AbpEfCoreNavigationHelper.cs index 4a57f0803c..50a8a121d3 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/ChangeTrackers/AbpEfCoreNavigationHelper.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/ChangeTrackers/AbpEfCoreNavigationHelper.cs @@ -36,7 +36,7 @@ public class AbpEfCoreNavigationHelper : ITransientDependency return; } - var entryId = GetEntityId(entityEntry); + var entryId = GetEntityEntryIdentity(entityEntry); if (entryId == null) { return; @@ -81,7 +81,7 @@ public class AbpEfCoreNavigationHelper : ITransientDependency continue; } - var entryId = GetEntityId(principal.ToEntityEntry()); + var entryId = GetEntityEntryIdentity(principal.ToEntityEntry()); if (entryId == null || !EntityEntries.TryGetValue(entryId, out var abpEntityEntry)) { continue; @@ -120,7 +120,7 @@ public class AbpEfCoreNavigationHelper : ITransientDependency continue; } - var entryId = GetEntityId(principal.ToEntityEntry()); + var entryId = GetEntityEntryIdentity(principal.ToEntityEntry()); if (entryId == null || !EntityEntries.TryGetValue(entryId, out var abpEntityEntry)) { continue; @@ -158,7 +158,7 @@ public class AbpEfCoreNavigationHelper : ITransientDependency return true; } - var entryId = GetEntityId(entityEntry); + var entryId = GetEntityEntryIdentity(entityEntry); if (entryId == null) { return false; @@ -169,7 +169,7 @@ public class AbpEfCoreNavigationHelper : ITransientDependency public virtual bool IsNavigationEntryModified(EntityEntry entityEntry, int navigationEntryIndex) { - var entryId = GetEntityId(entityEntry); + var entryId = GetEntityEntryIdentity(entityEntry); if (entryId == null) { return false; @@ -184,11 +184,14 @@ public class AbpEfCoreNavigationHelper : ITransientDependency return navigationEntryProperty != null && navigationEntryProperty.IsModified; } - protected virtual string? GetEntityId(EntityEntry entityEntry) + protected virtual string? GetEntityEntryIdentity(EntityEntry entityEntry) { - return entityEntry.Entity is IEntity entryEntity && entryEntity.GetKeys().Length == 1 - ? entryEntity.GetKeys().FirstOrDefault()?.ToString() - : null; + if (entityEntry.Entity is IEntity entryEntity && entryEntity.GetKeys().Length == 1) + { + return $"{entityEntry.Metadata.ClrType.FullName}:{entryEntity.GetKeys().FirstOrDefault()}"; + } + + return null; } public void Clear() diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DomainEvents_Tests.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DomainEvents_Tests.cs index c24d4567f4..6032d33a2f 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DomainEvents_Tests.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DomainEvents_Tests.cs @@ -187,15 +187,15 @@ public abstract class DomainEvents_Tests : TestAppTestBase>(data => + LocalEventBus.Subscribe>(_ => { personCreatedEventCount++; return Task.CompletedTask; }); - LocalEventBus.Subscribe>(async data => + LocalEventBus.Subscribe>(async _ => { - entityUpdatedEventTriggered = !entityUpdatedEventTriggered; + entityUpdatedEventTriggered = true; await PersonRepository.InsertAsync(new Person(Guid.NewGuid(), Guid.NewGuid().ToString(), new Random().Next(1, 100))); }); @@ -230,7 +230,7 @@ public abstract class DomainEvents_Tests : TestAppTestBase>(data => + LocalEventBus.Subscribe>(_ => { throw new Exception("Should not trigger this event"); }); @@ -263,6 +263,18 @@ public abstract class DomainEvents_Tests : TestAppTestBase>(async _ => + { + oneToOneEntityUpdatedEventTriggered = true; + }); + LocalEventBus.Subscribe>(async _ => + { + oneToOneAndOneToOneEntityUpdatedEventTriggered = true; + }); + entityUpdatedEventTriggered = false; await WithUnitOfWorkAsync(async () => { @@ -271,9 +283,13 @@ public abstract class DomainEvents_Tests : TestAppTestBase { var entity = await AppEntityWithNavigationsRepository.GetAsync(entityId); @@ -281,9 +297,11 @@ public abstract class DomainEvents_Tests : TestAppTestBase>(data => + LocalEventBus.Subscribe>(_ => { throw new Exception("Should not trigger this event"); }); @@ -323,6 +341,18 @@ public abstract class DomainEvents_Tests : TestAppTestBase>(async _ => + { + oneToManyEntityUpdatedEventTriggered = true; + }); + LocalEventBus.Subscribe>(async _ => + { + oneToManyAndOneToManyEntityUpdatedEventTriggered = true; + }); + entityUpdatedEventTriggered = false; await WithUnitOfWorkAsync(async () => { @@ -331,9 +361,13 @@ public abstract class DomainEvents_Tests : TestAppTestBase { var entity = await AppEntityWithNavigationsRepository.GetAsync(entityId); @@ -341,9 +375,11 @@ public abstract class DomainEvents_Tests : TestAppTestBase>(data => + LocalEventBus.Subscribe>(_ => { throw new Exception("Should not trigger this event"); }); @@ -439,7 +475,7 @@ public abstract class AbpEntityChangeOptions_DomainEvents_Tests LocalEventBus.Subscribe>(data => { - entityUpdatedEventTriggered = !entityUpdatedEventTriggered; + entityUpdatedEventTriggered = true; return Task.CompletedTask; });