views:

40

answers:

2

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 help. Thanks in advance.

A: 

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.

Grant Crofton
A: 

@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:

  1. 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.

  2. 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.

third
It depends what you want to do with them, but I can't imagine saving a stream would work too well - you couldn't access the properties via SQL, so you'd have to load all of the entities from the database, deserialize them and look through them with code to find anything. The link I posted saves each version of the history as a separate record, so you'll end up with loads of history records for a changed object, each one with perhaps one or two differences. Takes a lot of space, but flexible and easy to implement - and space isn't usually much of a problem these days anyway.
Grant Crofton
Thanks. I am concerned if there's a performance hit if we save it as a stream. If we save entities as records then we stumble to another challenge: how do we save the properties of the entity that are collections? For example, how do we save the Suppliers property (List<Supplier>) of a Product? The proper way at least.
third