New Posts New Posts RSS Feed: How do others handle detail lines?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

How do others handle detail lines?

 Post Reply Post Reply
Author
BillG View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
Post Options Post Options   Quote BillG Quote  Post ReplyReply Direct Link To This Post Topic: How do others handle detail lines?
    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
Back to Top
midnit View Drop Down
Senior Member
Senior Member
Avatar

Joined: 22-Jun-2009
Location: Charlotte
Posts: 112
Post Options Post Options   Quote midnit Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down