EditableRootListBase problem on second update

EditableRootListBase problem on second update

Old forum URL: forums.lhotka.net/forums/t/2260.aspx


Ivan posted on Thursday, February 01, 2007

I have noticed posible problem whit EditableRootListBase (dynamic collection). I have EditableRootListBase with some items bind to grid on form. If I update some of those item they get updated in database immediatly. If I try to update them again nothing happens (only if using remote data portal).

Since I'm using CSLA for some thime I tried to see what is going on and notice that items in Dynamic colelction have EditableRootListBase collection as a parent before first update (and after insert) but during second update their parent is null and they don't get saved (updated). CSLA is 2.1.2.

I have pinpointed this problem to the foloving method in EditableRootListBase:

public virtual void SaveItem(int index)
{
   bool raisingEvents = this.RaiseListChangedEvents;
   this.RaiseListChangedEvents = false;
   _activelySaving =
true;
   T item =
this[index];
   int editLevel = item.EditLevel;

   
// commit all changes
   for (int tmp = 1; tmp <= editLevel; tmp++)
      item.AcceptChanges();

   
try
   
{
   
// do the save
      
this[index] = (T)item.Save();
   }
   
finally
   
{
   
// restore edit level to previous level
   
for (int tmp = 1; tmp <= editLevel; tmp++)
      item.CopyState();

   _activelySaving =
false;
   
this.RaiseListChangedEvents = raisingEvents;
   }
   
   
this.OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, index));
}

After this[index] = (T)item.Save() item looses parent becuse it isn't returned from remote dataportal and during folowing updates, because of chek for parent in BusinessBase.AcceptChangesComplete where it is null, nothing hapens. I have added this[index].SetParent(this); after this[index] = (T)item.Save()  to set parent for updated item and everything seems to works OK.

Copyright (c) Marimer LLC