SaveItem(index) is called when CancelNew at EditableRootListBase?!?

SaveItem(index) is called when CancelNew at EditableRootListBase?!?

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


phucphlq posted on Monday, September 11, 2006

My business object has a property required. An exception is throw when I call CancelNew.

This is my code:

_CurrentIndex = _List.IndexOf(_List.AddNew());

T CurrentObject = _List[_CurrentIndex];

if (CurrentObject.IsNew)

    _List.CancelNew(_CurrentIndex); // SaveItem(index)  is called

else

   CurrentObject.CancelEdit();

 

This function is from EditableRootListBase:

protected override void RemoveItem(int index)

{

// delete item from database

T item = this[index];

item.Delete();

SaveItem(index); // WHY

...

}

ajj3085 replied on Monday, September 11, 2006

Why are you deleteing the item from the database immediately?  That won't work with n-level undo.

phucphlq replied on Monday, September 11, 2006

Not me, reason of problem is CSLA call SaveItem(index) after delete. See below code:

This function is from EditableRootListBase:

protected override void RemoveItem(int index)

{

// delete item from database

T item = this[index];

item.Delete();

SaveItem(index); // WHY

...

}

ajj3085 replied on Tuesday, September 12, 2006

Ahh ok.  Thought that wsa your code..

Well this make sense.  Delete only marks the object as deleted.  SaveItem instructs the objecto Save itself.  Since the object knows it was marked as deleted, it should intereperate the Save to mean 'delete myself from the database.'

The problem sounds like your object is also New however.  A new object should do nothing when IsDeleted is true and IsNew is true, and the object should simply be removed from the collection.

Is your object overriding Save?  What are you trying to acomplish with the code you posted?  Where is it being called?  I'd think you wouldn't have to do anything special; the grid and bindingsource should be calling AddNew and CancelNew for you..

phucphlq replied on Tuesday, September 12, 2006

I think this is a bug in EditableRootListBase. To fix this bug, I suggest to change RemoveItem function of EditableRootListBase.

protected override void RemoveItem(int index)

{

// delete item from database

T item = this[index];

item.Delete();

if(!IsNew)

     SaveItem(index);

...

}

RockfordLhotka replied on Tuesday, September 12, 2006

Yes, it is a bug in ERLB. I fixed it in a similar manner a few days ago, so the fix will be in the beta release.

ajj3085 replied on Wednesday, September 13, 2006

Nevermind... jjust saw the next thread Smile [:)]

Rocky,

Is the beta with this fixed released?  Or was it included in the last refresh?

RockfordLhotka replied on Wednesday, September 13, 2006

The beta I put up on Sept 12 has this change.

Copyright (c) Marimer LLC