Browse Source
Skip `PublishEntityDeletedEvent/PublishEntityUpdatedEvent` if only foreign keys have changed.
pull/19523/head
maliming
2 years ago
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4
2 changed files with
21 additions and
0 deletions
-
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs
-
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DomainEvents_Tests.cs
|
|
|
@ -328,6 +328,12 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext, |
|
|
|
ApplyAbpConceptsForModifiedEntity(entry); |
|
|
|
if (entry.Properties.Any(x => x.IsModified && (x.Metadata.ValueGenerated == ValueGenerated.Never || x.Metadata.ValueGenerated == ValueGenerated.OnAdd))) |
|
|
|
{ |
|
|
|
if (entry.Properties.Where(x => x.IsModified).All(x => x.Metadata.IsForeignKey())) |
|
|
|
{ |
|
|
|
// Skip `PublishEntityDeletedEvent/PublishEntityUpdatedEvent` if only foreign keys have changed.
|
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
if (entry.Entity is ISoftDelete && entry.Entity.As<ISoftDelete>().IsDeleted) |
|
|
|
{ |
|
|
|
EntityChangeEventHelper.PublishEntityDeletedEvent(entry.Entity); |
|
|
|
|
|
|
|
@ -200,6 +200,11 @@ public abstract class DomainEvents_Tests<TStartupModule> : TestAppTestBase<TStar |
|
|
|
}); |
|
|
|
entityUpdatedEventTriggered.ShouldBeTrue(); |
|
|
|
|
|
|
|
LocalEventBus.Subscribe<EntityUpdatedEventData<AppEntityWithValueObjectAddress>>(data => |
|
|
|
{ |
|
|
|
throw new Exception("Should not trigger this event"); |
|
|
|
}); |
|
|
|
|
|
|
|
// Test with value object
|
|
|
|
entityUpdatedEventTriggered = false; |
|
|
|
await WithUnitOfWorkAsync(async () => |
|
|
|
@ -232,6 +237,11 @@ public abstract class DomainEvents_Tests<TStartupModule> : TestAppTestBase<TStar |
|
|
|
}); |
|
|
|
entityUpdatedEventTriggered.ShouldBeTrue(); |
|
|
|
|
|
|
|
LocalEventBus.Subscribe<EntityUpdatedEventData<AppEntityWithNavigationChildOneToOne>>(data => |
|
|
|
{ |
|
|
|
throw new Exception("Should not trigger this event"); |
|
|
|
}); |
|
|
|
|
|
|
|
entityUpdatedEventTriggered = false; |
|
|
|
await WithUnitOfWorkAsync(async () => |
|
|
|
{ |
|
|
|
@ -258,6 +268,11 @@ public abstract class DomainEvents_Tests<TStartupModule> : TestAppTestBase<TStar |
|
|
|
}); |
|
|
|
entityUpdatedEventTriggered.ShouldBeTrue(); |
|
|
|
|
|
|
|
LocalEventBus.Subscribe<EntityUpdatedEventData<AppEntityWithNavigationChildOneToMany>>(data => |
|
|
|
{ |
|
|
|
throw new Exception("Should not trigger this event"); |
|
|
|
}); |
|
|
|
|
|
|
|
entityUpdatedEventTriggered = false; |
|
|
|
await WithUnitOfWorkAsync(async () => |
|
|
|
{ |
|
|
|
|