Browse Source

Provide an option to disable updating the aggregate root when the navigation property changes.

pull/22752/head
maliming 1 year ago
parent
commit
f1e797a35b
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 7
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/AbpEntityChangeOptions.cs
  2. 5
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs

7
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Events/AbpEntityChangeOptions.cs

@ -8,6 +8,13 @@ public class AbpEntityChangeOptions
/// </summary> /// </summary>
public bool PublishEntityUpdatedEventWhenNavigationChanges { get; set; } = true; public bool PublishEntityUpdatedEventWhenNavigationChanges { get; set; } = true;
/// <summary>
/// Default: true.
/// Update the aggregate root when any navigation property changes.
/// Some properties like ConcurrencyStamp,LastModificationTime,LastModifierId etc. will be updated.
/// </summary>
public bool UpdateAggregateRootWhenNavigationChanges { get; set; } = true;
public IEntitySelectorList IgnoredNavigationEntitySelectors { get; set; } public IEntitySelectorList IgnoredNavigationEntitySelectors { get; set; }
public AbpEntityChangeOptions() public AbpEntityChangeOptions()

5
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs

@ -274,7 +274,7 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext,
continue; continue;
} }
if (entityEntry.State == EntityState.Unchanged) if (EntityChangeOptions.Value.UpdateAggregateRootWhenNavigationChanges && entityEntry.State == EntityState.Unchanged)
{ {
ApplyAbpConceptsForModifiedEntity(entityEntry, true); ApplyAbpConceptsForModifiedEntity(entityEntry, true);
} }
@ -478,7 +478,8 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext,
} }
} }
if (EntityChangeOptions.Value.PublishEntityUpdatedEventWhenNavigationChanges) if (EntityChangeOptions.Value.PublishEntityUpdatedEventWhenNavigationChanges &&
EntityChangeOptions.Value.UpdateAggregateRootWhenNavigationChanges)
{ {
foreach (var entry in AbpEfCoreNavigationHelper.GetChangedEntityEntries() foreach (var entry in AbpEfCoreNavigationHelper.GetChangedEntityEntries()
.Where(x => x.State == EntityState.Unchanged) .Where(x => x.State == EntityState.Unchanged)

Loading…
Cancel
Save