CSLA Discussion

CSLA Discussion

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


mayurimalgave posted on Friday, September 12, 2014

Hello...

I have written a BO class viz. PersonEdit. It has PersonAddresses & PersonPhones as child properties.

Each address or phone may have tags such as Home,Office,School.

The following DataPortal_Create() code runs successfully in Silverlight. But in wpf, it doesn't work. Can anyone tell me the reason behind it. 

protected override void DataPortal_Create()
        {
            PersonAddressesEditList addressList = new PersonAddressesEditList();
            foreach (var addressTag in AddressTagNVList.GetList())
            {
                PersonAddressEdit obj = DataPortal.CreateChild<PersonAddressEdit>(this.Id);
                obj.AddressTagId = addressTag.Key;
                obj.AddressTagDescription = addressTag.Value;
                obj.ShareUnshareContent = "Share";
                addressList.Add(obj);
            }
            PersonPhonesEditList phoneList = new PersonPhonesEditList();
            foreach (var phoneTag in PhoneTagNVList.GetList())
            {
                PersonPhoneEdit obj = DataPortal.CreateChild<PersonPhoneEdit>(this.Id);
                obj.PhoneTagId = phoneTag.Key;
                obj.PhoneTagDescription = phoneTag.Value;
                obj.ShareUnshareContent = "Share";
                phoneList.Add(obj);
            }
            SetProperty(PersonAddressesProperty,addressList);
            SetProperty(PersonPhonesProperty,phoneList);
            base.DataPortal_Create();
        }

For WPF,If I comment this code, then the Person object is saved.

RockfordLhotka replied on Tuesday, September 16, 2014

If you comment out this code then your object is saved?

mayurimalgave replied on Tuesday, September 16, 2014

Yes..If I comment this code, then only the Person object gets saved,but its children doesn't save.

JonnyBee replied on Tuesday, September 16, 2014

Well, that´s likely to be a problem in your code.

You try to pass the "parent" id in the DataPortal_Create method. I suspect that you will get the actual id in the DataPortal_Insert method and should pass this value down to the children in your code.

In order to make your code perform more optimized you should also do all the initialization of child objects in their Child_Create method and not set properties after the object is returned as:

 

So IMO you should pass the adressTag/phoneTag object to the DataPortal.CreateChild method and NOT the this.Id. 

this.Id will typically only be determined after the Save and should be passed on in DataPortal.UpdateChild / FieldManager.UpdateChildren so the child objects get their parent Id as a parameter. 

 

Copyright (c) Marimer LLC