What is the best practice for implementing a database revisioning?
Assume i have a table called Test, and another table for revisioning called Test_Rev.
It is supposed that i will track Test’s records changes into the Test_Rev table.
Before saving, i get the changed entities so that i can revision the tables which needs to be revisioned.
I’ve made a separate thread using the Producer-Consumer pattern and then pass the entities that i need to revision to that thread.
Using the visitor pattern, i’ve extended the behavior of my classes so that i can revision them.
It works well but i need to know the best practice.
A friend told me to make the revisioning as a trigger on the tables which i need to revision.
By the way, I’m using VS 2010, SQL Server 2005, Entity Framework
It depends if you are happy with logic in database. If you don’t have problem with it use DB triggers. If you want to keep logic in your application override
SaveChangesin derivedObjectContextand run your revisioning (adding revision entities) before you executebase.SaveChanges. The only problem can be “auditing” newly added entities with autogenerated key – the key is known only after callingbase.SaveChanges. So in such case you must audit added entities after saving changes and callbase.SaveChangesagain.I don’t think there is any reason to have separate thread for that – moreover
ObjectContextis not thread safe.