I think this problem is a value/reference instantiate problem in Object Oriented languages like C#. But I'm newbie and I don't know how to turnaround.
I have a method with this piece of code:
List<CSpropr> listActionpropr = CSpropr.searchList(actionCondition); // Get a list of all records of table PROPR for the 'actioncondition' specified
// For each record...
foreach (CSpropr instance in listActionpropr)
{
instance.ValName = "John";
instance.ValPhone = 323234232;
instance.update(); // This make and UPDATE of the record in DB
}
Later in the same method, I want to use the first version of listActionpropr, before the update. To make a sort of rollback. But when I iterate the listActionpropr variable I get the list of records with the changes in Name and Phone values. For example:
foreach (CSApropr instance1 in listActionpropr )
{
instance1.update();
}
Is there an elegantly way to preserve the value without create a new search to other variable? Like this:
List<CSpropr> listActionpropr = CSpropr.searchList(actionCondition); // Get a list of all records of table PROPR for the 'actioncondition' specified
List<CSpropr> preservedList = CSpropr.searchList(actionCondition); // Get a list of all records of table PROPR for the 'actioncondition' specified
// For each record...
foreach (CSpropr instance in listActionpropr)
{
instance.ValName = "John";
instance.ValPhone = 323234232;
instance.update(); // This make and UPDATE of the record in DB
}
....
foreach (CSApropr instance1 in preservedList )
{
instance1.update();
}