Edit level mismatch in AcceptChanges CSLA 4.1 Silverlight

Edit level mismatch in AcceptChanges CSLA 4.1 Silverlight

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

JJLoubser posted on Friday, February 04, 2011


why this error:

Edit level mismatch in AcceptChanges at Csla.Core.UndoableBase.AcceptChanges(Int32 parentEditLevel) at Csla.Core.UndoableBase.Csla.Core.IUndoableObject.AcceptChanges(Int32 parentEditLevel, Boolean parentBindingEdit) at Csla.Core.FieldManager.FieldDataManager.Csla.Core.IUndoableObject.AcceptChanges(Int32 parentEditLevel, Boolean parentBindingEdit) at Csla.Core.BusinessBase.AcceptingChanges() at Csla.Core.UndoableBase.AcceptChanges(Int32 parentEditLevel) at Csla.Core.BusinessBase.ApplyEdit() at Csla.Xaml.CslaDataProvider.Save()



my bo object has a child of elements

I use it in a viewmodel for a treeview in the xaml for building a observable collection from it

all actions are working, but when I save I get the above error.

the viewmodels that are use in depedence objects are this is set ManageObjectLifetime = false;

that was the error with one of our other projects, but not in this case

what else could be wrong.




RockfordLhotka replied on Friday, February 04, 2011

Do you have a viewmodel for any child objects? ViewModelBase, by default, manages the Model object's lifetime - which means it calls BeginEdit automatically. It wouldn't call ApplyEdit automatically for a child object though.

Usually what you do for a viewmodel that represents a child object, is in the viewmodel's constructor you set ManageObjectLifetime = false.

JJLoubser replied on Sunday, February 06, 2011

yes, must we only have one viewmodel, because we have a viewmodel for every diffrent child.

class layout:


- ProductCatelogueEditViewModel<CatelogueER> : parent         (child of ProductER without viewmodel link to CSLAAdapter)

- ProductCatelogueCategoryViewmodel<CatelogueCategoryEC> : child of above  and himself

- ProductCatelogueItemViewmodel<CatelogueItemEC> : child of above

for the treeview observablecollection for the xaml there are:

- ProductCatelogueRootItem is a DependencyObject that contains ProductCatelogueEditViewmodel

- ProductCatelogueCategoryItem is a DependencyObject that contains CatelogueCategoryViewmodel

- ProductCatelogueItem is a DependencyObject that contains CatelogueItemViewmodel

the treeview are build out of above items.


RockfordLhotka replied on Monday, February 07, 2011

I think about viewmodel objects as having the same parent-child hierarchy as the business objects they contain. Only the root viewmodel should have ManageObjectLifetime as true, so child viewmodels must explicitly set this value to false.

JJLoubser replied on Tuesday, February 08, 2011

yes thanks, my parent's manageobjectlifetime was true and all the children was false, the 1st child manageobjectlifetime is also false from the parent, that was not the problem, the problem was this:


Csla.RelationshipTypes.Child was Csla.RelationshipTypes.lazyload //lazyload do not work

in Parent:

private static readonly PropertyInfo<CatalogueER> CatalogueProperty = RegisterProperty<CatalogueER>(p => p.Catalogue, Csla.RelationshipTypes.Child);
public CatalogueER Catalogue
        if (!FieldManager.FieldExists(CatalogueProperty) || ReadProperty(CatalogueProperty) == null)
            return null; //new CatalogueER();
            return ReadProperty(CatalogueProperty);

        LoadProperty(CatalogueProperty, value);

this property is the 1st child and viemodel of the treeview in it are the category of category until items...


lol thanks man

Copyright (c) Marimer LLC