Hi,
In my program, there are two class, say, category and product, with each object of product hold a reference to the category it belongs to. When loading data from XML and store them in the database, a problem arise:
If I create a category object and store it in the database first, there will be dirty data when creating product failed.(I want each xml loading be transactional, thus if the user failed by some mistake, the database remains as before).
If I create product first, there will be no reference(CategoryID generated by database) for them. I also can validate all the products first, but there will be to much duplicated code in validation and object creation. What is the best practice?
Thanks in advance!