When an entity implements IFullAudited, and it is updated, it updates the LastModiefiedUserId, and LastModificationTime, and does not create a new row. Is it possible to configure it so that a new row is created, so that the old data before the update is preserved as well on an update?
13 Answer(s)
-
0
I think the way to go is to subscribe to event bus events, and then log changes to entities where applicable. Is there a way to subscribe to the event bus, so that I receive an event for any entity change?
I can see that I can subscribe to EntityCreatingEventData<TEntity>, for update create and delete, but I have to state the Entity type. Is there to not specify the entity type, so that I receive events for all entity changes?
thank you.
-
0
From the documentation on Handling Base Events:
you can implement IEventHandler<EventData> to handle all events in the application.
-
0
You can handle events by type of event data.
public class ActivityWriter : IEventHandler<TaskCompletedEventData>, IEventHandler<TaskCreatedEventData>, ITransientDependency { public void HandleEvent(TaskCompletedEventData eventData) { //TODO: handle the event... } public void HandleEvent(TaskCreatedEventData eventData) { //TODO: handle the event... } }
-
0
When I override ApplyAbpConceptsForDeletedEntity in Dbcontext, it gets called when an entity is deleted.
However, it also sometimes gets called when an entity is deleted, but an exception causes the unit of work to roll back the transaction.
The error causing the rollback is when I delete an entity before deleteing navigation properties on that entity, which then causes an foreign key violation. When this happens, I can see that ApplyAbpConceptsForDeletedEntity gets called, and then the AbpHandledExceptionData event fires afterwards.
I think this might be a bug, because I dont think that ApplyAbpConceptsForDeletedEntity should trigger if the entity was not really deleted from the database because of a UOW rollback.
-
0
"when the UOW is completed <ins>or</ins> when current transaction is committed"
To be clear, ApplyAbpConceptsForDeletedEntity executes when SaveChanges is called:
- explicitly, or
- automatically when the UOW is completed, or
- automatically when current transaction is committed (i.e. the outermost UOW is completed)
In cases 1 and 2, a rollback is still possible <ins>after</ins> (but it doesn't get called <ins>on</ins> a rollback).
-
0
What's your point?
ApplyAbpConceptsForDeletedEntity is called (https://github.com/aspnetboilerplate/aspnetboilerplate/blob/6eccadb5d454f8f3d26bbd330f0d1ffd0455cbd6/src/Abp.EntityFrameworkCore/EntityFrameworkCore/AbpDbContext.cs#L198:3hov3him/) [b:3hov3him]base.SaveChanges().