Object is Still Being Edited

Object is Still Being Edited

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


Frazer posted on Thursday, May 28, 2009

When I try to save changes to my BO, I get a ValidationException:  Object is still being edited...

As I have no need in my application for undo, I do not make explicit calls to BO.BeginEdit.

Basically, my logic is as follows:

BO.SomeProperty = "new value";
BO.Save();

Am I missing a concept - or should I be looking for an error in my BO implementation?

 

 

 

 

Frazer replied on Thursday, May 28, 2009

When I examine BO.EditLevel, it has a value of 1.

This would suggest to me that BeginEdit has been called.  As I mentioned in my previous post, I do not call BeginEdit explicitly in my code - so... what am I missing here?  

rsbaker0 replied on Thursday, May 28, 2009

If your object is bound to the user interface, then the calls to the IEditableObject interface by the data bindings are automatically raising the edit level of your object.

You have to unbind your object before saving it, and then rebind the result returned from saving afterwards. If you search the forum for CslaActionExtender or RebindUI, I think you'll find threads on this.

RockfordLhotka replied on Thursday, May 28, 2009

The Using CSLA .NET 3.0 ebook has a chapter specifically covering this sort of issue.

Based on that information, Miguel created the CslaActionExtender control for CSLA 3.6 to take care of most of the details - because it turns out to be a pain to deal with the unbind/rebind issues by hand.

CslaActionExtender is covered to some degree in the Expert 2008 Business Objects book, though that book doesn't have a specific focus on Windows Forms.

JoeFallon1 replied on Thursday, May 28, 2009

In addition to the other comments code like this is always wrong:

BO.Save();

It should always be:
mBO = mBO.Save();

You have to update the local variable with the returned BO from the DataPortal.

Joe


Frazer replied on Friday, May 29, 2009

Thanks to all who responded - I have been able to get this working the help provided.  Joe's post explained why my updates didn't seem to be persisting and I was using a dynamic editable list as a datasource for a listview - which explained the EditLevel != 0. 

 

Copyright (c) Marimer LLC