Browse Source

Skip `PublishEntityDeletedEvent/PublishEntityUpdatedEvent` if only foreign keys have changed.

pull/19523/head
maliming 2 years ago
parent
commit
8307a6f356
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 6
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs
  2. 15
      framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DomainEvents_Tests.cs

6
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.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);

15
framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/DomainEvents_Tests.cs

@ -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 () =>
{

Loading…
Cancel
Save