Search code examples
aspnetboilerplate

Versionable Entities


I´m working on a project using ASPNET Boilerplate where some entities must be versioned, so they have an Id and a versionNumber, where the same entity can have several versions like:

Documents:[
{Document:{id:1, version:1}}, 
{Docuemnt:{id:1, version:2}}]

So my question is if there is an easy way of doing this, like the implementation of Soft Delete, where I can intercept the update method so it creates a new version.


Solution

  • You can override ApplyAbpConcepts in your DbContext to create a new entity when your Document entity is modified, then reload the original entity so that its changes are not saved. CancelDeletionForSoftDelete does something similar.

    But just doing this won't work because primary key is unique. You can create a composite key.

    You will also have to handle relationships (i.e. foreign keys) to avoid linking to multiple versions.