I've just updated to abp v3.4.0 and i'm currently investigating the History tracking feature as i think this could be quite useful to me.
I'm just not sure how to actually get the information out and how it relates to the rest of the Abp system.
So this is how i'm thinking it should work in my mind.
Now the thing i am not sure about is how to get the Entity History information from the Updated event.
I've tried using the repository private readonly IRepository<EntityChangeSet,long> _entityChangeRepository;
in the IEventHandler but this doesn't seem to "Save Changes" before the Updated event is triggered.
So what would be the correct way to access the Entity History information? Is it even possible to access it through an Event?
Thanks!
Entity History is for audit purposes.
EntityChangeSet
is saved after your entity is updated (and after its Updated
event is triggered).
Is it even possible to access it through an Event?
Bad news: You cannot access it (without extensive hacking) through your entity's Updated
event.
Good news: But you can access it through an event.
So what would be the correct way to access the Entity History information?
Access it in the Created
event of EntityChangeSet
entity.
Implement an event handler for IEventHandler<EntityCreatedEventData<EntityChangeSet>
.
There, you can:
EntityChangeSet.EntityChanges
,EntityChange.ChangeType
is EntityChangeType.Updated
,EntityChange.PropertyChanges
,PropertyChange
, and finallyAgain, Entity History is for audit purposes so this isn't straightforward. But it's now possible! :)