EntityHistory: Get entity instance/revision for specific date
Hi,
is there a functionality to retrieve an instance/revision of an audited entity for a specific datetime?
Something like:
// get revision of specific record of MyEntityType for given datetime
var entityRevision = await _entityRevisionManager.GetAsync<MyEntityType>(theId, theDatetime);
// get revision of all records of MyEntityType for given datetime
var entityRevisions = await _entityRevisionManager.GetListAsync<MyEntityType>(theDatetime);
I know there are EntityChangeInfos and EntityPropertyChangeInfos from the AuditingModule. I could build these revisions from this Infos but Iยดm curious if there is an existing solution. If not it could be a cool feature for the framework.
I would like to help implementing it, if it gets an accepted feature request.
Greetings ๐
Hi @tntwist,
There is no functionality for this. You should code it yourself. ๐ It may be good feature for framework too, we should discuss it. ๐
@cotur Thanks for the fast reply.
I think the core idea should be that this entity revisions are generated on demand from the entity change infos and entity property change infos. Storing this revisions in the database seems a bit over, since we have the change infos already stored. What do you think about this?
I assume that the creation/generation of the revisions is then relatively "expensive", so maybe if they would be cached once generated could help for future requests.
This are some ideas I have related to this.
For getting the entity changes we could use the AuditLogRepository: modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs
This method returns all entity changes for an entity: https://github.com/abpframework/abp/blob/2a0cad46ff1a8f179cb4268ca86ad610cc497ab6/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs#L75
Do you think it would be good to create all revisions when requested? Since we already load all changes.
Thinking about that the current revision could change any time we might subscribe to entity change events to update the revisions.
I think such a feature is not easy to implement because entity type can be change during the history and re-constructing the current entity type with a historical data may be hard or impossible.
Instead of mapping, a JSON/Dictionary style object can be generated, but it will be just to show somewhere.
We can take this as a feature request, but with low priority to work on. I suggest you to implement yourself if you really need it.