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 f8dcffee52..07ea443fdf 100644 --- a/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs +++ b/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs @@ -510,6 +510,12 @@ public abstract class AbpDbContext : DbContext, IAbpEfCoreDbContext, { foreach (var complexPropertyEntry in complexPropertyEntries) { + var complexPropertyInfo = complexPropertyEntry.Metadata.PropertyInfo; + if (complexPropertyInfo != null && complexPropertyInfo.IsDefined(typeof(DisableAuditingAttribute), true)) + { + continue; + } + foreach (var propertyEntry in complexPropertyEntry.Properties) { yield return propertyEntry; diff --git a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/Auditing_Tests.cs b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/Auditing_Tests.cs index b614b43fb7..d9667f23e2 100644 --- a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/Auditing_Tests.cs +++ b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/Auditing_Tests.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using NSubstitute; +using Shouldly; using Volo.Abp.Auditing.App.Entities; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; @@ -911,6 +912,76 @@ public class Auditing_Tests : AbpAuditingTestBase AuditingStore.ClearReceivedCalls(); #pragma warning restore 4014 } + + [Fact] + public async Task Should_Not_Update_Modification_Audit_Properties_When_Only_Disabled_Complex_Property_Changes() + { + var entityId = Guid.NewGuid(); + var repository = ServiceProvider.GetRequiredService>(); + + using (var uow = _unitOfWorkManager.Begin()) + { + var entity = new AppEntityWithComplexProperty(entityId, "Test Entity") + { + ContactInformation = new AppEntityContactInformation + { + Street = "First Street", + Location = new AppEntityContactLocation + { + City = "First City" + } + }, + DisabledContactInformation = new AppEntityContactInformation + { + Street = "Disabled Street", + Location = new AppEntityContactLocation + { + City = "Disabled City" + } + } + }; + + await repository.InsertAsync(entity); + + await uow.CompleteAsync(); + } + + using (var uow = _unitOfWorkManager.Begin()) + { + var entity = await repository.GetAsync(entityId); + entity.Name = "Updated Test Entity"; + + await repository.UpdateAsync(entity); + await uow.CompleteAsync(); + } + + DateTime? lastModificationTime; + using (var uow = _unitOfWorkManager.Begin()) + { + var entity = await repository.GetAsync(entityId); + lastModificationTime = entity.LastModificationTime; + lastModificationTime.ShouldNotBeNull(); + await uow.CompleteAsync(); + } + + await Task.Delay(10); + + using (var uow = _unitOfWorkManager.Begin()) + { + var entity = await repository.GetAsync(entityId); + entity.DisabledContactInformation.Street = "Updated Disabled Street"; + + await repository.UpdateAsync(entity); + await uow.CompleteAsync(); + } + + using (var uow = _unitOfWorkManager.Begin()) + { + var entity = await repository.GetAsync(entityId); + entity.LastModificationTime.ShouldBe(lastModificationTime); + await uow.CompleteAsync(); + } + } } public class Auditing_DisableLogActionInfo_Tests : Auditing_Tests