Comments (3)
You can access the DbContext inside your custom action with
.AuditEntityAction<AuditLog>((ev, entry, auditEntity) =>
{
var dbContext = entry.GetEntry().Context;
// ...
});
So I guess you could explicitly load the related entities with:
dbContext.Entry(entity).Reference(e => e.Unit).Load();
dbContext.Entry(entity).Reference(e => e.Status).Load();
from audit.net.
You can access the object being updated from the AuditEntityAction, for example:
Audit.Core.Configuration.Setup()
.UseEntityFramework(ef => ef
.AuditTypeMapper(t => typeof(AuditLog))
.AuditEntityAction<AuditLog>((ev, entry, auditEntity) =>
{
// Since "IncludeEntityObjects" is configured, we can get the entity from entry.Entity
// (otherwise, you could use entry.GetEntry().Entity)
if (entry.Entity is Entity entity)
{
var status = entity.Status;
var unit = entity.Unit;
// do whatever you need with the Status and Unit objects
}
auditEntity.ActionType = entry.Action;
...
}
)
.IgnoreMatchedProperties(true)
);
from audit.net.
I tried that, but the object come as null
I found that if I .Include(e => e.Status)
before calling await context.SavesChangesAsync()
, it will load correctly! But, will this imply that I need to Include
all sub-entities before?
Could I somehow load the dbcontext inside the AuditEntityAction
, and include as needed, to avoid loading tons of unrelated properties? If yes, how? I have an idea on how to implement the second part, but currently having problems instantiating the db context there
from audit.net.
Related Issues (20)
- Error on inserting Audit Data HOT 2
- EF Core value updates not audited HOT 3
- EF Core value updates are not audited HOT 13
- Custom field empty in Entries Array HOT 3
- Bump Microsoft.Bcl.AsyncInterfaces HOT 1
- Limited configuration of MongoDB provider HOT 1
- Related object causes multiple audit entries HOT 3
- Question for WebApi: Audit only on statuscodes HOT 2
- How to use WebApi / Serilog with .Net 4.7.2 HOT 9
- Extra Double Quote in PostgreSqlDataProvider Generated SQL HOT 2
- Sometimes when auditing to CosmosDB a CosmosException occurs HOT 5
- Since the new version of mongo-csharp-driver The Jobject for AuditTarget cannot be serialized/deserialized HOT 2
- AuditCommandInterceptor IncludeReaderResults = true results in "DataReader Open" error HOT 9
- Missing Method Exception: Microsoft.EntityFrameworkCore.Metadata.IEntityType.GetProperties() HOT 3
- Audit.EntityFramework.Core add support for EF8 Complex Types HOT 1
- Feature Request: New MongoDB interaction extension to audit a MongoDB .NET Driver instance HOT 1
- How to audit entities that have been changed\deleted because of on cascade behavior? HOT 13
- How to ingest data to AzureTableStorage month wise in the AuditTrail implementation using Audit.NET? HOT 2
- Not available to use dbContext in .UseDbContext<MyDbContext> in Audit.Core.Configuration.Setup HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from audit.net.