UpdateChildren correction

UpdateChildren correction

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


Codelines posted on Friday, August 22, 2014

Please, correct me if I'm wrong, but FieldDataManager.UpdateChildren shouldn't be like this:

        public void UpdateChildren(params object[] parameters)

        {

            if (_propertyList == null) return;

            foreach (var pi in _propertyList)

            {

                if ((pi.RelationshipType & RelationshipTypes.Child) > 0)

                {

                    var item = _fieldData[pi.Index];

                    if (item != null)

                    {

                        object obj = item.Value;

                        if (obj is IEditableBusinessObject || obj is IEditableCollection)

                            Csla.DataPortal.UpdateChild(obj, parameters);

                    }

                }

            }

        }

The way it is now, all objects referenced by the businessobject are being treated as children even when they aren't.

jteneglio replied on Saturday, August 23, 2014

If i'm not mistaken only the properties who are set to be Child will be saved

         private static readonly PropertyInfo<ChildObjectName> ChildObjectNameProperty = RegisterProperty<ChildObjectName>(p => p.ChildObjectName Csla.RelationshipTypes.Child);

 

But what I do is when i include child object that should not be saved I use an Info object (ReadOnlyBase) So I don't get this problem.

 

hope this helps

Codelines replied on Saturday, August 23, 2014

Jean, 

sometimes you will need to reference the same object twice in the object graph and only one reference must be treated as child. In other situations you could reference an object from another object graph and that object must not be treated as a child. In an earlier versions, the default for the RelationshipType property of the PropertyInfo class was Relationshiptypes.Child, but now I've seen that is Relationshiptypes.None. 

 

jteneglio replied on Saturday, August 23, 2014

Ok so those it work with the relatioinshiptypes.none?

If you can show some code maybe it will help us see what the problem is

Codelines replied on Sunday, August 24, 2014

In CSLA 4.3.14, UpdateChildren doesn't verify RelationshipChild and calls UpdateChild for any object referenced by the businessobject:

    public void UpdateChildren(params object[] parameters)

    {

      foreach (var item in _fieldData)

      {

        if (item != null)

        {

          object obj = item.Value;

          if (obj is IEditableBusinessObject || obj is IEditableCollection)

            Csla.DataPortal.UpdateChild(obj, parameters);

        }

      }

    }

If RelationshipType was verified, we could use RelationshipTypes.None to avoid the UpdateChild for those objects that aren't children.

Copyright (c) Marimer LLC