locked
Linq Context Scope; Cancelling Entity Updates RRS feed

  • Question

  • Can someone PLEASE help with a problem that is driving me nuts.  The application is in WPF.

    I need to manage the lifespan of my ModelDataContext objects, and I cant seem to get it right.

    As an example...say I have Invoice Objects.  Each invoice has a Customer, and Invoice Items, etc.  as per standard invoices.

    Scenario 1.  Adding a new item.
    In a list of current invoices, a user can choose to add a new invoice, in a popup window.  The prefered method of managing scope seems to be (and it makes sense) to create a new context on the edit window.  That was if the user wants to cancel the changes we simply abandon the data context. 

    BUT when saving the changes, the list doesnt get refreshed properly in the parent context.  Refreshing, a list of Invoices can get me the invoice properties updated, but doesnt seem to update information in my list derived from the line items.  Why not?

    Scenario 2.  Editing an existing item.
    Editing an existing item, makes sense to me to do the same as with a new item; create a new context, and either savechanges or throw it away.

    BUT...Scenario 3.  Editing a NEW item.
    What if I have a list of invoices, and I want to add new invoices, but only commit all the changes at the same time.  I cant keep creating new datacontexts because I dont want to submit each one to the database until the end of editing.  Plus if a user adds an invoice, adds a second, and then goes back to the first to make a change, it wont exist in the database yet, so a new datacontext wouldnt pick it up?

    This is the scenario I really want to support. 

    I think the piece of the puzzle I am missing is how to abandon changes to an invoice and its line items held in memory that does not exist in the database yet?  Is this possible?
    Sunday, May 10, 2009 7:03 PM

Answers

All replies