I have been debating this for a while now and would like to hear how others handle this situation. You have 2 classes, Invoice and InvoiceDetail. Invoice is the parent and InvoiceDetail is the child. The user creates a new invoice by clicking a button so you call Invoice.Create() and it creates a new invoice object in memory. They add a detail line by clicking add on a grid. Which of the following do you use or is there another I am missing?
#1 - Create an InvoiceDetail object by calling InvoiceDetail.Create which creates an object in memory and link the child to the parent. Call Save on the step. The problem is if the user cancels the whole invoice, then you have to remove that object.
#2 - Create an InvoiceDetail object by calling InvoiceDetail.Create which creates an object in memory and link the child to the parent. Do not save the detail line but add it to a ObservableCollection of Invoice Details. When the invoice is saved, the Invoice parent and the list of children are saved to the appropriate tables. If the invoice is cancelled, then the Invoice object is cancelled and the ObservableCollection children are removed from memory and the list is destroyed.
I used to do #1 but I am beginning to do #2 now for new projects. Any thoughts out there?
Bill