Reputation: 433
I'm developing e-commerce system, at the moment I do Product class, which works as container of a lot of entities such as photos, product parameters (name value collection), etc. I know that everything here should be stored in database (ms sql).
So such use case will be popular: 1) Customer open some product to edit it 2) Customer adds couple new photos 3) Customer changes some parameters of the product 4) Customer clicks on Save button.
So the question is what is the best way to track changes made? I can calculate them in repository class by comparing data in class to be saved and the same class just loaded from db, but it seems a bit ugly thing to do.
I also think that it's not good idea to pollute Product class with this tracking code.
Upvotes: 2
Views: 872
Reputation: 6741
You describing UnitOfWork pattern
There are existed implementations of this pattern for EntitiFramework (example) and
NHibernate (example).
Upvotes: 1
Reputation: 1012
Do the change tracking with Entity Framework. http://blogs.msdn.com/b/adonet/archive/2009/06/10/poco-in-the-entity-framework-part-3-change-tracking-with-poco.aspx
Upvotes: 2