Audit EF is saving an Inserted action when no insert actually happened.
See original GitHub issueFull reproduction: https://github.com/VictorioBerra/Audit.NET_EF_Issue200_RelatedEntitys
There are a few important things to note. One, is the automapper profile:
cfg.CreateMap<CatUpdateViewModel, Cat>()
.ForMember(dest => dest.CatBreedLine,
opts => opts.MapFrom(src => src.CatBreedIds.Select(id => new CatBreedLine()
{
CatId = id,
CatBreedId = src.Id
})));
You can see, for every CatUpdateViewModel
that I map to a Cat entity, it creates new instances of CatBreedLine
.
Anyways, if you run the sample, look at the console output, notice no second insert for a CatBreedLine
happened, yet Audit.EF saves an Insert audit record!!
Also, I would like EF to NOT bump the Created*/Updated* stuff for the CatBreedLine
too since the record didnt technically ever change…
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Cannot Audit on Insert Entity Framework.I am stuck can you ...
Once you've audited the item, set the key (bool) to true, to signify it has been audited. Or another option is to instead...
Read more >How To Track Entity Changes With EF Core | Audit Logging
0:30 IAuditableEntity 2:30 Using EF interceptors for auditing 6:09 Configuring the interceptor 7:27 Auditing in action.
Read more >Interceptors - EF Core
The result is a SaveChangesAudit entity with a collection of EntityAudit entities, one for each insert, update, or delete. The interceptor then ...
Read more >Audit Trail Implementation in ASP.NET Core with Entity ...
I will create a very basic CRUD Application using .NET 5 MVC, Microsoft Identity, and Entity Framework Core. Once this is done, we...
Read more >Entity Framework - Get identity value in SavinChanges event
Note The identity column value will be returned only after the inserted statement committed successfully. 1. Insert the Entity Object. 2. Save ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m closing this since it doesn’t seem to be considered as an issue for EF, it’s more a design decision and I don’t think this behavior is going to change.
So for your case, you should probably
Include()
theCatBreedLine
on theCat
retrieval and have some logic instead of the VM->Cat mapping that overrides the lines.Unfortunately, my Cat example was a huge simplification of a much bigger project with many relationships and entities and generic repos 😬 so it wont be that easy. But i appreciate the advice.