Difference between save and savechanges in lightswitch
-
Thursday, July 19, 2012 8:55 AM
Hi
What is the difference between
this.save() and this.DataWorkspace.ApplicationData.SaveChanges();
Regards
Karan Gupta
All Replies
-
Thursday, July 19, 2012 11:39 AMModerator
The first one, this.Save, is found in screen methods, & causes the changes made during that screen to be saved. Underneath the covers, it's calling this.DataWorkspace.ApplicationData.SaveChanges.
The second one, this.DataWorkspace.ApplicationData.SaveChanges, is working at the Data Source level & causes the changes made during the life of the DataWorkspace to be saved.
In what scenario are you considering using either of them?
Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands 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. - Proposed As Answer by Miroslav Marinković Thursday, July 19, 2012 1:03 PM
- Marked As Answer by Dino HeModerator Thursday, July 26, 2012 2:17 AM
-
Tuesday, July 24, 2012 12:20 PM
Hi Yann
Sorry for the late reply. Can you please elaborate this with the help of an example.
-
Wednesday, July 25, 2012 5:01 AMModeratorNot without you giving me a scenario to work with, sorry.
Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands 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. -
Wednesday, July 25, 2012 8:03 AM
Hi Yann
Thanks for the reply. I am not looking for the scenario in which I can use both the methods i.e. save() and savechanges(). But I am looking for 2 scenarios where save() will work fine and other scenario where savechanges() will work fine.
-
Wednesday, July 25, 2012 1:24 PM
Hi Karan, For example, in screen command method, if you just call SaveChangs method instead of Save method, you won't get validaton message if there is a validation error, and the screen won't be froze, if the savechangs takes a lot of time you will see the difference.
- Edited by ryan lin chinese Wednesday, July 25, 2012 1:40 PM
-
Thursday, July 26, 2012 8:34 AM
Hi ryan lin chinese
I have created a employee table which contains 2 fields
1. EmployeeName (string)
2. Age(integer)
I have put a validation that if the age is lesser than 18 then give a validation error message.
Now when I enter the data and click save button which contains this.save() code I am getting thei error - "Please correct data entry errors and try to save again."
and when I click the button which contains this.Dataworkspace.ApplicationData.SaveChanges() then I am getting this error - "The operation cannot be performed because one or more objects are invalid. Please inspect the ValidationException.ValidationResults property for more information."
Have I missed something while trying a POC.
Please advice
Regards
Karan Gupta
-
Thursday, July 26, 2012 9:54 AMModerator
Calling the SaveChanges method on a data service (ApplicationData) will throw an exception if the save operation did not complete successfully. Such exceptions can be caused by:
- Validation errors
- Concurrency conflicts
- Connection errors and timeouts
This is not a complete list, but gives you an idea of the types of issues that can occur. The method throws the exceptions to allow you to handle the exceptions in your code and possibly provide an automated way of recovering from the problems.
Calling the Save method on the screen calls the SaveChanges method on the data service at some point (as Yann has mentioned) and handles specific exceptions to provide a decent experience to the end user. It handles, among others, concurrency and validation exceptions. Concurrency exceptions are handled by showing the concurrency resolver dialog to allow the end user to manually determine how to resolve conflicts. Validation exceptions are handled by showing the message that you saw: "Please correct data entry errors and try to save again."
Justin Anderson, LightSwitch Development Team
- Proposed As Answer by Yann DuranModerator Monday, February 04, 2013 11:00 AM
-
Thursday, January 31, 2013 8:58 AM
Hello, I have a problem regarding "dirty" data in a DataGrid at startup and probably is depended to Save() vs. SaveChanges(), but really I don't have idea what happens
DataGrid cache rows- Edited by Yann DuranModerator Monday, February 04, 2013 10:59 AM Made link clickable

