Skip to content

Commit 7b55fef

Browse files
authored
Merge pull request #13 from PandaTechAM/development
Sync audit base ignores now version check
2 parents 1236320 + 838df24 commit 7b55fef

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

src/EFCore.AuditBase/AuditEntityBase.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel.DataAnnotations;
2+
using System.ComponentModel.DataAnnotations.Schema;
23

34
namespace EFCore.AuditBase;
45

@@ -14,6 +15,9 @@ public abstract class AuditEntityBase
1415
[ConcurrencyCheck]
1516
public int Version { get; private set; } = 1;
1617

18+
[NotMapped]
19+
internal bool IgnoreInterceptor { get; set; }
20+
1721
public void MarkAsUpdated(long? userId, DateTime? updatedAt = null)
1822
{
1923
UpdatedAt = updatedAt ?? DateTime.UtcNow;
@@ -28,8 +32,10 @@ public void MarkAsDeleted(long? userId, DateTime? updatedAt = null)
2832
UpdatedByUserId = userId;
2933
Version++;
3034
}
35+
3136
public void SyncAuditBase(AuditEntityBase source)
3237
{
38+
IgnoreInterceptor = true;
3339
UpdatedAt = source.UpdatedAt;
3440
UpdatedByUserId = source.UpdatedByUserId;
3541
Deleted = source.Deleted;

src/EFCore.AuditBase/EFCore.AuditBase.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
<PackageReadmeFile>Readme.md</PackageReadmeFile>
99
<Authors>Pandatech</Authors>
1010
<Copyright>MIT</Copyright>
11-
<Version>3.0.3</Version>
11+
<Version>3.0.4</Version>
1212
<PackageId>Pandatech.EFCore.AuditBase</PackageId>
1313
<Title>Pandatech EFCore AuditBase</Title>
1414
<PackageTags>Pandatech, library, audit, optimistic lock, tracking, efcore, soft delete, versioning</PackageTags>
1515
<Description>Pandatech.EFCore.AuditBase provides a robust auditing solution for EF Core applications, ensuring traceability and integrity of entity modifications. It seamlessly integrates auditing capabilities into your EF Core entities, enforcing best practices for entity state changes, deletion handling, and versioning to support concurrency control. Ideal for applications requiring a reliable audit trail and compliance with data handling standards.</Description>
1616
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-efcore-audit-base</RepositoryUrl>
17-
<PackageReleaseNotes>Nuget updates</PackageReleaseNotes>
17+
<PackageReleaseNotes>Sync audit base ignores now version check</PackageReleaseNotes>
1818
</PropertyGroup>
1919

2020
<ItemGroup>

src/EFCore.AuditBase/Interceptors/AuditPropertyValidationInterceptor.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@ private static void ValidateAuditMethodUsage(DbContext context)
3232
{
3333
var entries = context.ChangeTracker
3434
.Entries<AuditEntityBase>()
35-
.Where(e => e.State == EntityState.Modified);
35+
.Where(e => e.State == EntityState.Modified)
36+
.ToList();
37+
38+
var ignoreInterceptor =
39+
entries.Any(x => x.CurrentValues[nameof(AuditEntityBase.IgnoreInterceptor)] as bool? ?? false);
40+
41+
if (ignoreInterceptor)
42+
{
43+
return;
44+
}
3645

3746
foreach (var entry in entries)
3847
{

test/EFCore.AuditBase.Demo/EFCore.AuditBase.Demo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.3" />
12-
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.3.1" />
12+
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.0" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

0 commit comments

Comments
 (0)