Delete a Child Enitity until Main Entity is Save.

Posts   
 
    
Posts: 7
Joined: 10-Sep-2008
# Posted on: 03-Dec-2009 16:38:41   

Need some quidance. 2.6 Self-Service Winform App

Simple example. I have an order enitity which has a collection of orderDetail entities. When a user deletes an order detail record I would like to have it removed from the grid but I do not want to physically delete the entity unless the main enitity passes validation without this child entity and is saved.

Is there a way to make the order detail collection act as if it was just another property of the order entity. If the detail collection is changed then the order entity is then dirty.

I am in a situation where the collection must be valid. For example: On order must have at least one line item.

My real world example is: I am paying an employee $100 this $100 must be distributed to one or more accounts and must total $100. Employee Pay Enitity is saved with $100 and 2 EmployeePayAccount records are created (Account A $50, Account B $50). This passes validation (PayEntity Amount = sum of PayAccounts).

If I were to edit this record and delete PayAccount B. (PayAccount B is deleted from the database and is gone forever) The Employee Pay Enitity is still saved and is not dirty. PayAccountA is saved and not dirty. However this Pay Enitity is no longer valid because PayEntity Amount does not equal the sum of the Pay Accounts.

If I do nothing after this, I have a record that is already saved in an invalid state.

I don't want to physically delete PayAccount B until the pay entity is valid and saved or if changes are canceled then PayAccount B is not deleted.

Sorry for rambling on.

Thanks Dan

Just found the UnitOfWork class this should do what I need it to do.

http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/SelfServicing/gencode_unitofwork.htm

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 03-Dec-2009 21:15:22   

Thats just what I was about to say - the UoW is exactly what you are after. The other one to look at is the RemovedEntitiesTracker. This keeps track of any entities removed from a collection so you can delete them at the same time as you save the entity with the UoW.

Matt