locked
Pending Changes RRS feed

  • Question

  • Hi,

    Is there any way to know if you have pending changes in your DataServiceContext?
    I'm basically trying to figure out when I can enable a save button, I would assume the DataServiceContext can tell me if some changes need to be sent to the server.

    Thanks,
    Friday, October 3, 2008 4:08 PM

Answers

  • Hi ,

     The DataServiceContext has collections called as Entities and Links .

     Querying these collections can give you the information you need.

     It would look something like this ,

     

    Code Snippet

    private bool HasPendingChanges(DataServiceContext context) {

    //Check if any entities need to be saved

     return context.Entities.Any(ed => ed.State != EntityStates.Unchanged) ||

    //Check if any links need to be saved

     context.Links.Any(ld => ld.State != EntityStates.Unchanged);

    }

     

     

    The basic premise behind this is that Entities and Links  that have been commited to the store are in the Unchanged State.

    By querying the  entities and the links collection to see if any of them are NOT in the unchanged state , you can determine if there are any pending changes to be commited.

    Friday, October 3, 2008 4:25 PM
    Moderator

All replies

  • Hi ,

     The DataServiceContext has collections called as Entities and Links .

     Querying these collections can give you the information you need.

     It would look something like this ,

     

    Code Snippet

    private bool HasPendingChanges(DataServiceContext context) {

    //Check if any entities need to be saved

     return context.Entities.Any(ed => ed.State != EntityStates.Unchanged) ||

    //Check if any links need to be saved

     context.Links.Any(ld => ld.State != EntityStates.Unchanged);

    }

     

     

    The basic premise behind this is that Entities and Links  that have been commited to the store are in the Unchanged State.

    By querying the  entities and the links collection to see if any of them are NOT in the unchanged state , you can determine if there are any pending changes to be commited.

    Friday, October 3, 2008 4:25 PM
    Moderator
  • Thanks a lot, that's exactly what I was looking for.
    Friday, October 3, 2008 5:12 PM
  • Friday, October 3, 2008 5:57 PM
    Moderator
  • Hello,

    This method is very nice, but I have another question. How can I detect that some kind of change has occurred. In other words, is there some kind of event that I can subscribe to in order to detect that someone has changed something, i.e. added, edited, or removed and entity?


    Rossen Hristov
    Monday, May 30, 2011 12:36 PM