locked
Pending changes indicator (star) after discarding changes RRS feed

  • Question

  • Hi,

    I have code that displays a modal window, which updates some records in my DataSource by doing some computations (but does not yet persist these changes to the database). The user then has the option to keep these updated records, or discard them by clicking a Cancel button. Clicking the Cancel button calls entity.Details.DiscardChanges(), which does indeed discard the changes (additionally, this.DataWorkspace.ApplicationData.Details.HasChanges is false, indicating again that the changes actually were discarded.

    However, LightSwitch is still marking the screen as well as the previously modified DataItem with the pending changes indicator (star). This enables the user to click the Save button which will execute server based code that I do not want to be executed (since the DataItem did not actually end up being updated).

    Why does Lightswitch think that the current screen contains pending changes even though I discarded them and HasChanges returns false? Is there a way to get rid of this behavior by code?

    Thanks for your help!

    Tobias

    Friday, August 23, 2013 7:57 AM

All replies

  • Do you have an additional data source in which changes could have been made and haven't been discarded? The logic that shows the star indicator basically asks all data sources if they have changed and shows if one of them has changes.

    Justin Anderson, LightSwitch Development Team

    Friday, August 23, 2013 8:01 AM
    Moderator
  • Hi Justin,

    Thanks for the quick reply!

    I have two data sources; however for both HasChanges returns false after the modal window has been closed via the cancel button.

    Friday, August 23, 2013 8:05 AM
  • You can try implementing the SaveChanged_Executing method for each of the data services, then reproduce the problem, try to save and see if there are, in fact, changes being propagated to the server. You would check the results of:

    this.DataWorkspace.ApplicationData.Details.GetChanges()

    to see what entities have changed, and then you can inspect the state of each entity and the properties to see what has changed. If something is changed and HasChanges is really reporting false, then there may be a bug in the HasChanges property of data services.

    If everything points to a bug, please log a bug on the Connect site. Please provide as much detail, reproduction steps, and your project if you can.

    Just as an FYI, the save button on both standard shells is always enabled, regardless of whether changes exist or not.


    Justin Anderson, LightSwitch Development Team

    Friday, August 23, 2013 8:17 AM
    Moderator
  • Hi Justin,

    thanks for the advice.

    I just found out that if I query this.DataWorkspace.ApplicationData.GetChanges() during the Screen_Saving method, it does return the modified dataitem which I thought had been discarded, and it does return true for HasChanges.

    This is very strange behavior, since but for the star indicator the changes appear to have been discarded until the user hits save.

    Does LS somehow initialize two different instances of my entity, one which is visible in my datagrid and from which I appear to have discarded all changes, and one from which the star indicator is computed and which is handed to the database during screen_Saving?

    Thanks again for your help!

    Tobias

    Friday, August 23, 2013 8:55 AM
  • Does LS somehow initialize two different instances of my entity, one which is visible in my datagrid and from which I appear to have discarded all changes, and one from which the star indicator is computed and which is handed to the database during screen_Saving?

    In the sense that the client and the server are two completely different processes and thus a single entity would be represented as two objects (one on the client, one on the server), then yes. But in the same process, there is only one instance of an entity from a given workspace.

    Are you sure you are not creating a new data workspace to which you are making changes and then discarding and also making changes in the screen's data workspace and not discarding those changes?


    Justin Anderson, LightSwitch Development Team

    Friday, August 23, 2013 11:53 PM
    Moderator