ApplyEdit

ApplyEdit

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


culprit posted on Wednesday, May 20, 2009

Dear CSLA,
I am still a little confused I guess on the EditState. I have a BB with several child BLBs. In one scenario I have a BLB that if the user chooses a new product the BLB is assigned to a new blank collection and then items are added to the BLB based on the new product chosen. In this case I always get an "Edit level mismatch in AcceptChanges" when executing ApplyEdit. I am performing the unbinding as specified by the tracker app and it is working in other fairly complex BBs. I have tried to unbind just the BLB BindingSource before manually rebuilding the BLB but with the same result. Could someone please enlighten me?

Sincere Thanks,
Rob

Jack replied on Thursday, May 21, 2009

I've had issues with EditState and saving whenever I've added collection items that were not marked as children (MarkAsChild).  Sometimes I create dummy rows or template placeholders for the users to fill in required data.

Might not be the issue but worth double checking.

jack

culprit replied on Thursday, May 21, 2009

Just for future reference I found the problem in this scenario. I was clearing the BLB collection by setting a new object to the collection:

_blb = BLB.NewObject

which is a factory method which fires the private constructor to return a new object.

I fixed this by simply clearing the collection by firing: _blb.clear. I know, well, duh, but the forest for the trees and all that muck.

RockfordLhotka replied on Thursday, May 21, 2009

Calling Clear() may work - but remember that this causes all current items to be marked as deleted and moved to the deletedList inside the collection. So they aren't entirely gone until you save the object graph - in which case the data they refer to in the database will be deleted.

If you really want to just create a new collection without deleting the items it contains you'll need to do something different.

It is possible to set the field to a new collection - but if you do that then you must get the new collection's edit level to match the parent object. In 3.6 the LoadProperty() helper method does this for you, but you can do it yourself too - just search the forum for "lazy loading" and you'll probably find a thread or two where I show the code you need to write (just a couple while loops).

Though even the while loops are a lot simpler in 3.6 because of the addition of an interface you can use to manipulate the edit level of an object.

Copyright (c) Marimer LLC