How to edit objects withouth saving them?
-
Thursday, August 09, 2012 12:34 PM
I have a Grid on my screen displaying the list of entities in a table, all normal... but I have a procces on my screen that asks the user some data and it changes in memoy the displayed objects. This works perfect, but the only problem is that LS marks those objects as edited and when the user closes the window, LS lauchs the saving prompt.
This screen is only for "Viewing" not editing, I just only need to show the user the differences over the data with different inputs, but not to save them. How can I avoid LS marking those objects or avoid the prompt?
Any suggestions?
Tnx
SebaXOR
All Replies
-
Thursday, August 09, 2012 2:10 PM
You could create public variable(s) in the Screen_Activated() method that record the default inputs when the screen was opened and then revert the values back when the screen is closed/saved.
Also, remember that you can overwrite the saving method for the screen. I am not sure if you can prevent the save dialog from showing up but you can definitely prevent the new values from being saved over the old data.
If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer." By doing this you'll help people find answers faster.
- Edited by c4ctopus Thursday, August 09, 2012 2:10 PM
-
Thursday, August 09, 2012 2:31 PM
By default, there is one DataWorkspace for a screen. All data that the screen loads is in the context of that DataWorkspace. Any changes to entities that were loaded within that DataWorkspace will cause the screen to be "dirty" and prompt for saving. You have the option of creating your own DataWorkspace within your screen code however. This will isolate any data within that DataWorkspace from the screen's DataWorkspace. So as long as the entity you want to edit does not have to come from the screen's DataWorkspace, you can make edits to it without affecting the dirtiness of the screen. To create a DataWorkspace, call this.Application.CreateDataWorkspace().
Learn more about DataWorkspace:
- Proposed As Answer by Yann DuranModerator Friday, August 10, 2012 2:36 AM
-
Thursday, August 09, 2012 6:19 PMYeah... that is what I have now.. but can's prevent the saving dialog
SebaXOR
-
Thursday, August 09, 2012 6:20 PMI have a doubt... it wn't prompt me to save on the real workspace.. but.. It will prompt me to save in the "virtual" one, isn't it?
SebaXOR
-
Thursday, August 09, 2012 6:24 PMThe screen only knows about it's default DataWorkspace. If there exist any changes to entities within that DataWorkspace, it will prompt you. If you've explicitly created your own DataWorkspace, by calling CreateDataWorkspace, the screen will not prompt you to save if the only changes to entities are within that explicitly created DataWorkspace. In other words, you are responsible for saving the DataWorkspace that you created (or not, if you don't want to save the changes); the screen won't do that for you.
-
Thursday, August 09, 2012 6:45 PM
The new workspace will have the same schema of the original, and access to the same database?
Or I will have to map my entities there and copy the in-memory objects?
SebaXOR
-
Thursday, August 09, 2012 6:56 PMThe DataWorkspace gives you access to all your data, to multiple databases if you have them. Two DataWorkspaces provide access to the same data but they are isolated from one another. For example, if you load the same entity into two different DataWorkspaces and make a change to that entity's property, then the same entity that was loaded in the second DataWorkspace won't see that change until the first DataWorkspace is saved and then you re-query that entity. So, in-memory changes are isolated between DataWorkspaces.
-
Friday, August 10, 2012 2:56 AM
I understand conceptually, but I'm not pretty sure how to put that in code..
partial void MovimientosCajaInforme_InitializeDataWorkspace(List<IDataService> saveChangesTo)
{
var tempWS = Application.CreateDataWorkspace();
}I only have this..
1. I have to assign my WS to the saveChangesTo? (I think no.. but that confuses me with the second question)
2. I have a query in my Screen properties, so I should delete that query and by code bind the data? or how should I query my data?
This is unusual for the things I have done in LightSwitch.. as I said.. I understand the concept, but don't know how to code it.
Thanks, and sorry for my ignorance.
SebaXOR
-
Friday, August 10, 2012 12:59 PMIn order to help, I'll need to understand more what your scenario is. How is your screen setup? How and why are you making changes to the entity within code? Any other interesting details?
-
Friday, August 10, 2012 4:19 PM
My screen is basically composed by a grid wich lists all the entities of a Table...
I have a class on my UsersCode client, this has an extension method attached to the specific entity. The extension method asks for a parameter that is a Property of the screen, when user input, the method is called and it proccess all the entities in the list...
That is basically what my screen does.
Thanks
SebaXOR
-
Monday, August 13, 2012 9:03 AM
Any Suggestions.. or I need to add more info? Is basically a SearchScreen template with some filters, one of the screen properties is the responsible for the proccess over the data at the client side.
Thanks
SebaXOR
-
Monday, August 13, 2012 1:28 PM
So given the entity that you would like to edit, I would create a new DataWorkspace and execute a query to return back that same entity. It would essentially be a copy of that entity and associated with that new DataWorkspace, not the screen's DataWorkspace. Now you are free to make any edits you wish on that entity without affecting the screen's data.
- Marked As Answer by Otomii LuModerator Monday, August 20, 2012 1:30 AM
-
Monday, August 20, 2012 7:51 AM
But with a single entity would be easy.. but reload a list of them is more complex... and slow.. or al least the way I think .. If I would be able to "change" the original DataWorkspace from the begin of the screen.. it would be better...
Something like..
InitializeDataWorkspace(saveChangeTo)
{
saveChangesTo = new DataWorkspace();}
And make the screen to use that Workspace.. but not to capture the saving events..
SebaXOR

