Print Page | Close Window

How do others handle detail lines?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2225
Printed Date: 07-Apr-2025 at 6:56pm


Topic: How do others handle detail lines?
Posted By: BillG
Subject: How do others handle detail lines?
Date Posted: 13-Oct-2010 at 11:29am
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



Replies:
Posted By: midnit
Date Posted: 19-Oct-2010 at 9:51am
#2 without hesitation.
 
Invoice basically having its own ViewModel when 'Add Detail' is commanded we InvoiceDetail.Create(Invoice) which returns the new InvoiceDetail which goes into the VM's InvoiceDetails Collection. Throw in some housekeeping code. Very desirable options. As in canceling the InvoiceDetail, not the Invoice, or rolling back to various states of the InvoiceDetail.



Print Page | Close Window