From f1e797a35b65ae5adabacbb0ee597367212658ee Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 23 Apr 2025 16:41:14 +0800 Subject: [PATCH] Provide an option to disable updating the aggregate root when the navigation property changes. --- .../Abp/Domain/Entities/Events/AbpEntityChangeOptions.cs | 7 +++++++ .../Volo/Abp/EntityFrameworkCore/AbpDbContext.cs | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/AbpEntityChangeOptions.cs b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/AbpEntityChangeOptions.cs index a42b921068..5710bf7187 100644 --- a/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/AbpEntityChangeOptions.cs +++ b/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/AbpEntityChangeOptions.cs @@ -8,6 +8,13 @@ public class AbpEntityChangeOptions /// public bool PublishEntityUpdatedEventWhenNavigationChanges { get; set; } = true; + /// + /// Default: true. + /// Update the aggregate root when any navigation property changes. + /// Some properties like ConcurrencyStamp,LastModificationTime,LastModifierId etc. will be updated. + /// + public bool UpdateAggregateRootWhenNavigationChanges { get; set; } = true; + public IEntitySelectorList IgnoredNavigationEntitySelectors { get; set; } public AbpEntityChangeOptions() diff --git a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs index 626daf0bb4..d68616e69f 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs @@ -274,7 +274,7 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, continue; } - if (entityEntry.State == EntityState.Unchanged) + if (EntityChangeOptions.Value.UpdateAggregateRootWhenNavigationChanges && entityEntry.State == EntityState.Unchanged) { ApplyAbpConceptsForModifiedEntity(entityEntry, true); } @@ -478,7 +478,8 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, } } - if (EntityChangeOptions.Value.PublishEntityUpdatedEventWhenNavigationChanges) + if (EntityChangeOptions.Value.PublishEntityUpdatedEventWhenNavigationChanges && + EntityChangeOptions.Value.UpdateAggregateRootWhenNavigationChanges) { foreach (var entry in AbpEfCoreNavigationHelper.GetChangedEntityEntries() .Where(x => x.State == EntityState.Unchanged)