Edit Level Mismatch in BussinesObject Child

Edit Level Mismatch in BussinesObject Child

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


Antonio Sandoval posted on Tuesday, April 07, 2009

I have something like this:

DepartmentsList (ERLB )
...|----RolesList (ERLB )
...|----ObjectsList (ERLB )
............|---ObjectMap (BussinesBase, MarkAsChild)

And the binding:

DepartmentsList _departments = DepartmentsList.GetDepartmentsList();
departmentsListBindingSource.DataSource = _deparments;
rolesListBindingSource.DataSource = departmentsListBindingSource;
rolesListBindingSource.DataMember = "RolesList";
objectsListBindingSource.DataSource = departmentsListBindingSource;
objectsListBindingSource.DataMember = "ObjectsList";
objectMapBindingSource.DataSource = objectsListBindingSource;
objectMaptBindingSource.DataMember = "ObjectMap";

BindUI(){
_departments.BeginEdit();
departmentsListBindingSource.DataSource = _deparments;
}

Save(){
  UnbindbindingSource(objectMapBindingSource,false);
  UnbindbindingSource(objectsListBindingSource,false);
  UnbindbindingSource(rolesListBindingSource,false);
  UnbindbindingSource(departmentsListBindingSource,true);
  .....
  _departments.ApplyEdit()
  DepartmentsList tmp = _departments.Clone();
  _departments =tmp.Save();
}

When I add a new item to ObectsList into a datagrid the EditLevel comes back to 1 and the new item begins with EditLevel = 1. I'm using XtraGrid of devexpress. I don't know if it can be a bug of XtraGrid, or if I binding my controls in a wrong way.

Thanks in advance

RockfordLhotka replied on Tuesday, April 07, 2009

What version of CSLA are you using?

The current item in each bindingSource will have EditLevel of 1, because that item is current.

Antonio Sandoval replied on Tuesday, April 07, 2009

Hi rocky, thank you for your reply. I´m sorry for my mistake, I´m using 3.0.5 and the problem is because I´m doing this:

public ObjectsList ObjectsList{
  get{
      if(_objectsList == null){
              _ObjectsList = ObjectsList.GetObjectsListAsChild(this);
              _ObjectsList.ListChanged +=...
      }
      return _ObjectsList;
  }
}

So the editLevel of the existing childrens are never equals to the root.

When I do this before BeginEdit it saves correctly:
 foreach (Departments d in _departments)
 {
          foreach (Objects o in d.ObjectsList) { ObjectMap om = o.ObjectMap; }
          foreach (Roles r in d.RolesList)  { }
 }

But after save the EL are 0 to every object except for the first and the new child ObjectMap of the ObjectsList collection:

_departmentsNo [N].ObjectsList[0].ObjectMap EL = 1
_departmentsNo [N].ObjectsList[m].ObjectMap EL = 1

Where n is the current record and m is the new record.

Do you have any idea of what can be happening?

Thanks in advance.

RockfordLhotka replied on Wednesday, April 08, 2009

Yes, in 3.0, when implementing lazy loading, you need to manually bring the lazy loaded child's edit level up (or down) to match the parent object.

You can look at the 3.5 or higher code to see how this is done - but it is really just a couple while loops, somewhat like:

while (_objectsList.EditLevel > this.EditLevel) _objectsList.ApplyEdit();
while (_objectsList.EditLevel < this.EditLevel) _objectsList.BeginEdit();

If I remember correctly, you might have to cast _objectsList to be an ISupportUndo type (though that type might not exist until 3.5 either).

Anyway, that's the basic requirement.

In 3.5 and higher, when using managed backing fields, this is automatically done for you.

Antonio Sandoval replied on Wednesday, April 08, 2009

Ok, thank you rocky, I begun to migrate to 3.6.2.
I will to make some tests with the new version to see what happend.

Copyright (c) Marimer LLC