Implementing a version history feature
We are implementing a version history feature in our ERP application (Winforms/WCF), and we are looking for the best approach, so far we came up with 2 solutions:
1) Save the object state as binary in the database 2) Save the property names and values of the object and reconstruct it later when fetching
Or is there a better way to do this? Please he开发者_如何学Golp. Thanks in advance.
I depends how you're persisting things, but this Los Techies blog post describes the explicit modelling of historic entities in your code. Essentially you end up with a separate entity for the history. They're using NHibernate, but I think the same thing would apply if you were writing database code yourself.
Another approach to look at would be event sourcing, whereby every action that happens on your system is recorded as an event. As such, you have a record of every change that has happened to the entities you're interested in. However, unless you've been working this way from the start, I doubt it would be worth implementing just for version history.
@Lasse V. Karlsen, right now we are using POCO to persist objects. We are not using any ORM.
@Grant Crofton, looking at the solutions you mentioned, I think the first approach is more practical for us. We are planning to save the version history of any entity (Product, Purchase Order, Sales Order, etc) to one central table.
Since we are not using ORM, we are expirementing on ways how to save it on the DB:
Do we make the version entities as stream and save it on the DB? Is this even a good idea? It will make things easier for us.
Or do we save a every property name and its corresponding value of the object to the database? This way, everytime we need to get a version of an entity, we will just have to pull every attribute and values related to an object and reconstruct the object via code (I hope im not confusing you with this)
I apologise for not responding directly to each of your questions, this is an anonymous account and it seems I cannot login as the account I used earlier.
精彩评论