Using UnitOfWork2 while saving

Posts   
 
    
Posts: 13
Joined: 15-Jan-2006
# Posted on: 08-May-2006 22:26:40   

Hello,

I don't have a good understanding with how the Adapter scenario works when saving entities. I have an OrderEntity that has several linked entities: Order.Buyer, Order.Seller, Order.Products etc. If I use the following code:


UnitOfWork2 uow = new UnitOfWork2();

uow.AddForSave(order.BillingInformation, false);
uow.AddForSave(order.ShippingInformation, false);
uow.AddForSave(order.Buyer, false);
uow.AddForSave(order, false);

DataAccessAdapter adapter = new DataAccessAdapter();
uow.Commit(adapter, true);

When I do this, even the entities that I have not explicitly added to the UnitOfWork are saved. For example, I have an order.Seller entity that gets updated. How can I prevent the Seller entity from being updated? After making a call to ConstructSaveProcessQueues, I can see the SellerEntity in the _entitiesToUpdate field. I'm not sure why it is there.

By the way, I'm only using the UnitOfWork2 class because I want to be able to specify which entities to save and which to ignore. If there is a better way to accomplish this, please let me know.

Thanks, Jason

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 09-May-2006 02:49:49   

Is any related data between the entities being changed? If so then the Seller entity will be marked as dirty and saved. When using

AddForSave(IEntity2 entityToSave, bool refetch)

The save is marked recursive. You can "override" this by calling

AddForSave(IEntity2 entityToSave, IPredicateExpression restriction, bool refetch, bool recurse)

and setting recurse to false.

Posts: 13
Joined: 15-Jan-2006
# Posted on: 09-May-2006 03:54:01   

Thanks cblubb,

I assumed recurse was false by default. Guess I shouldn't assume simple_smile I'm changing the SellerEntity in memory, but I don't want to persist those changes to the database. Using the overload that has a recurse parameter should fix the problem.

Thanks, Jason