Edit Level Error Message in AcceptChanges

Edit Level Error Message in AcceptChanges

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


g.beraudo@castsoftware.com posted on Monday, October 22, 2012

Dear Rocky, Dear all, 

This is a question related to Edit Level... I'm sorry to ask the same question discussed in other thread.  I know this is a recurring trouble which comes from incorrect databinding (or more precisely unbinding).
I'm in WinForm with CSLA 4.3.

My root object has 4 children. 

I'm following the ProjectTracker saving pattern, re-read 'Export 2008 Business Objects' and loose some of my hair already.

In my Rebind() code, after unbinding and before calling .ApplyEdit() my root and all its children have their EditLevel = 1.

When calling myRoot.ApplyEdit() , an exception is raised in the following  (UndoableBase.cs) code:

    protected internal void AcceptChanges(int parentEditLevel)     {

      AcceptingChanges();

      if (this.EditLevel - 1 != parentEditLevel)

        throw new UndoException(string.Format(Resources.EditLevelMismatchException, "AcceptChanges"),

                            this.EditLevel, parentEditLevel, this.ToString(), String.Empty); //Exception there both EditLevel and parentEditLevel are set to 0

I do not understand why, as having all my EditLevel to 1 seems a correct prerequisite for the ApplyEdit() call. Am I wrong?

Am I missing something?

I have checked that all my controls use BindingSources, and that all BindingSources are correctly unbound. I do not know how to investigate this problem further.

Thanks for your feedback,

Gilles

JonnyBee replied on Monday, October 22, 2012

Well, basically this means that one of the child objects is already at EditLevel 0.

Do you have any inter-graph/using references that is not properly handled (private backing field marked with NonSerialized/NotUndoable)?

g.beraudo@castsoftware.com replied on Monday, October 22, 2012

Thanks Jonny for the valuable answer. This helpded me finding the cause.

I'm using managed fields only, but I was doing the following:

Bo r = Root.Child1(0);                        

Root.Child1.Remove(r);

Root.Child2.Add(r);  // replaced by Root.Child2.Add(r.Clone())

I assume that the r object was part of both the 'deleted list' of Child1 and the list of  Child2, thus undergoing twice the  ApplyChange(). 

Thanks again.

Gilles

Copyright (c) Marimer LLC