DeleteMe flag in Entity

Posts   
 
    
NickD
User
Posts: 224
Joined: 31-Jan-2005
# Posted on: 15-Feb-2006 20:48:30   

I looked just a bit for this but didn't find it so here goes:

There are "isNew" and "IsDirty" properties on an entity, so I'm curious about your thoughts on a "DeleteMe" property? Obviously, in a single instance scenario, the programmer should know if they should insert, update, or delete this instance. What I was imagining it could be used for is when there are x number of entities in an EntityCollection all with different states. One could call a DataAccessAdapter.DoWork() method that would insert, update, and delete based on those three properties.

Perhaps this already exists and I'm justing missing the boat.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 16-Feb-2006 02:56:18   

It does already exist. Take a look in the documentation about the UnitOfWork. It should do what you are asking.

// C#
CustomerEntity newCustomer = new CustomerEntity();
// ... fill newCustomer's data
AddressEntity newAddress = new AddressEntity();
// ... fill newAddress's data
newCustomer.VisitingAddress = newAddress;
newCustomer.BillingAddress = newAddress;
UnitOfWork uow = new UnitOfWork();
// add the customer for a recursive save action.
uow.AddForSave(newCustomer, true);

ProductEntity productToDelete = new ProductEntity(productID);
// add this product for deletion.
uow.AddForDelete(newProduct);

// commit all actions in one go
uow.Commit(new Transaction(IsolationLevel.ReadCommitted, "UOW"), true);