Skip to content

Commit 38ef299

Browse files
Remove audit page + add more documentations
1 parent 01e154b commit 38ef299

File tree

13 files changed

+106
-594
lines changed

13 files changed

+106
-594
lines changed
Lines changed: 72 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,107 @@
11
---
2-
Name: Audit
3-
LastMod: 2025-06-24
2+
Title: Auditing in Entity Framework Extensions
3+
MetaDescription: Learn how to use auditing options in Entity Framework Extensions for EF Core and EF6. Discover how to use `UseAudit`, `AuditEntries`, and `AuditEntry` to capture which data has been inserted, modified, or deleted in your database.
4+
LastMod: 2025-10-30
45
---
56

6-
# Audit
7+
# 📜 Auditing in Entity Framework Extensions/n Capture data that has been inserted, modified, or deleted in your database
78

8-
## Description
9+
The **audit feature** in Entity Framework Extensions lets you **track all changes** made to your database during any **bulk operation**.
910

10-
The EFE audit feature allows you to track changes of all modifications that happened in the database during the Bulk Operations. Also, it lets you create a history of who modified a table, what the old value was and the new value was.
11+
Once captured, you can **log the old and new values** directly in your database, write them to a log file, or simply use the audit results within your application.
12+
13+
The **audit feature** works with all bulk operations:
14+
15+
* [BulkInsert](/bulk-insert)
16+
* [BulkInsertOptimized](/bulk-insert-optimized)
17+
* [BulkUpdate](/bulk-update)
18+
* [BulkDelete](/bulk-delete)
19+
* [BulkMerge](/bulk-merge)
20+
* [BulkSynchronize](/bulk-synchronize)
21+
* [BulkSaveChanges](/bulk-savechanges)
1122

1223
## Key Features
1324

14-
- Allow getting a history of modifications
15-
- Allow storing the history in a database or log file
16-
- Allow tracking who, what, when a modification occurred
17-
- Allow knowing what the old and the new value are
25+
* Keep a complete history of all modifications
26+
* [Store audit data in a database](/save-audit-history-in-a-database) or a log file
27+
* Track **who**, **what**, and **when** a modification occurred
28+
* Compare **old values** and **new values** for every change
1829

1930
## Getting Started
2031

2132
To use the audit feature, you need to enable it and provide a list of the AuditEntry that will be populated during the operations.
2233

2334
```csharp
35+
// @nuget: Z.EntityFramework.Extensions.EFCore
36+
using Z.BulkOperations;
37+
using Z.EntityFramework.Extensions;
38+
2439
// Execute
2540
List<AuditEntry> auditEntries = new List<AuditEntry>();
2641
context.BulkMerge(list, options =>
2742
{
2843
options.UseAudit = true;
2944
options.AuditEntries = auditEntries;
3045
});
46+
```
47+
48+
## Class Definition
49+
50+
The audit feature includes **three main classes**:
51+
52+
* **AuditEntry**: Represents a row and contains information about the operation performed.
53+
* **AuditEntryItem**: Represents a column within a row and contains the old and new values.
54+
* **AuditActionType**: Defines the type of action performed (Insert, Update, Delete, etc.).
55+
56+
```csharp
57+
public class AuditEntry
58+
{
59+
public AuditActionType Action { get; set; }
60+
public DateTime Date { get; set; }
61+
public Dictionary<object, object> Metas { get; set; } // Hold any custom information you want to add
62+
public string TableName { get; set; }
63+
public List<AuditEntryItem> Values { get; set; }
64+
}
65+
```
3166

67+
```csharp
68+
public class AuditEntryItem
69+
{
70+
public string ColumnName { get; set; }
71+
public object NewValue { get; set; }
72+
public object OldValue { get; set; }
73+
}
3274
```
3375

34-
Try it: [.NET Core](https://dotnetfiddle.net/) | [.NET Framework](https://dotnetfiddle.net/)
76+
```csharp
77+
public enum AuditActionType
78+
{
79+
Delete,
80+
Insert,
81+
Update,
82+
SoftDelete,
83+
}
84+
```
3585

36-
## Scenarios
86+
## FAQ
3787

38-
- [Saving audit history in a database](../options/save-audit-history-in-a-database.md)
39-
- Saving the audit history in a log file
88+
### Why does enabling this option decrease performance?
4089

41-
## Options
90+
When this option is enabled, **additional SQL statements** are required to return all old and new values.
4291

43-
| Name | Description |
44-
|:-----------------------------------|:----------------------------------------------------------------------|
45-
|[UseAudit](../options/use-audit.md) | Gets or sets the `UseAudit` property. When the `UseAudit` property is `true`, the [AuditEntries](../options/audit-entries.md) property stores auditing metadata about `INSERTED`, `UPDATED`, and `DELETED` rows and values. |
46-
|[AuditEntries](../options/audit-entries.md) | Gets or sets the `AuditEntries` property. The `AuditEntries` property stores auditing metadata about `INSERTED`, `UPDATED`, and `DELETED` rows and values. This option requires setting the [UseAudit](../options/use-audit.md) property to `true`. |
92+
For some providers, such as **SQL Server**, it can no longer use `SqlBulkCopy` directly on the destination table when a column needs to be outputted. Instead, it must create a **temporary table**, which adds some extra overhead and reduces performance.
4793

48-
## Methods
94+
The impact can vary:
4995

50-
| Name | Description |
51-
|:-----------------------------------|:----------------------------------------------------------------------|
52-
|[AuditMode](../options/audit-mode.md) | The `AuditMode` method allows you to exclude or include properties from the auditing. |
96+
* It is **major** when the bulk strategy needs to be changed (for example, when `SqlBulkCopy` can’t be used).
97+
* It is **minor** when data was already being output, as the additional cost is limited.
5398

54-
## Entities
99+
## Conclusion
55100

56-
| Name | Description |
57-
|:-----------------------------------|:----------------------------------------------------------------------|
58-
|[AuditActionType](../options/audit-action-type.md) | The `AuditActionType` enum represents the action that has been performed (Delete, Insert or Update). |
59-
|[AuditEntry](../options/audit-entry.md) | The `AuditEntry` class represents the auditing row metadata that has been modified. |
60-
|[AuditEntryItem](../options/audit-entry-item.md) | The `AuditEntryItem` class represents the auditing value metadata of a row that has been modified. |
61-
|[AuditModeType](../options/audit-mode-type.md) | The `AuditModeType` enum represents if all properties should be included or excluded from the auditing. The default value is `AuditModeType.IncludeAll`. |
62-
|[ColumnMappingAuditModeType](../options/column-mapping-audit-mode-type.md) | The `ColumnMappingAuditModeType` enum represents if a specific property should be included or excluded from the auditing. The default value is `ColumnMappingAuditModeType.Inherit`. |
101+
The **audit feature** in Entity Framework Extensions is a powerful tool when you need to **keep track of what happens during your bulk operations**.
63102

64-
## FAQ
103+
With just a few lines of code, you can capture **who changed what and when**, store this information anywhere you want, and even compare old and new values for full transparency.
65104

66-
### Why enabling this option decreases the performance?
105+
While enabling auditing can slightly impact performance, it gives you complete visibility and control over your data changes — something that’s often worth the trade-off in real-world applications.
67106

68-
When enabling this option, additional SQL statements are required such as returning all old and new values.
107+
If you care about **data integrity, traceability, and accountability**, enabling auditing is one of the easiest ways to achieve it in your EF Core or EF6 projects.

entityframework-extensions.net/pages/documentations/options/audit-action-type.md

Lines changed: 0 additions & 64 deletions
This file was deleted.

entityframework-extensions.net/pages/documentations/options/audit-entries.md

Lines changed: 0 additions & 51 deletions
This file was deleted.

entityframework-extensions.net/pages/documentations/options/audit-entry-item.md

Lines changed: 0 additions & 61 deletions
This file was deleted.

entityframework-extensions.net/pages/documentations/options/audit-entry.md

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)