Override IsDirty = True after Delete

Override IsDirty = True after Delete

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


xAvailx posted on Tuesday, June 23, 2009

CSLA 3.6.1

When I mark an object for deletion, the object status changes to "IsDeleted=true, IsDirty=true". After saving (and updating my local variable reference), the status is "IsDeleted=false, IsDirty=true". I believe this is due to a call to MarkNew inside the dataportal. I would like to override this behavior on this specific object, so IsDirty is set to false after delete/save. What is the best way to approach this?

Thanks for any help.

RockfordLhotka replied on Tuesday, June 23, 2009

You can override Save() and reset the value after the operation is complete. Something like this:

public override CustomerEdit Save()
{
  var tmp = base.Save();
  tmp.MarkOld();
  return tmp;
}

 

xAvailx replied on Tuesday, June 23, 2009

Works like a charm, thx!

Wbmstrmjb replied on Wednesday, July 29, 2009

On this note, what is the point of MarkNew in the Delete? After the object is deleted, what good is IsNew and IsDirty?

RockfordLhotka replied on Wednesday, July 29, 2009

This is discussed in the book. If you use deferred deletion on a root object, or a single (non-list) child of a root, it is quite realistic for the UI to end up with a valid reference to the resulting object after the delete.

Obviously that object no longer matches data in the database, and so it meets the definition of being new. And its data no longer matches data in the database, so it meets the definition of being dirty.

If the object isn't marked accordingly, the UI would have a reference to an object that is known to be in an invalid state, which would almost certainly lead to unexpected bad behaviors.

Wbmstrmjb replied on Thursday, July 30, 2009

Ah ha! There it is. I had missed it. Thanks for the added explanation.

Copyright (c) Marimer LLC