Can not directly save a child object

Can not directly save a child object

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


decius posted on Monday, September 08, 2008

I must have took a wrong turn somewhere in developing this BO.  I have a Parent object that contains several properties (2 of them are child List objects).

To update the children in my data access, I call _myChildObject.Save() But I throw a NotSupportedException of "Can not directly save a child object".  If I'm not supposed to update my child objects this way, how is it supposed to be done?

Mary replied on Monday, September 08, 2008

Hi,

You can use the Update function in data-access region of your child object list for saving the child object.

protected override void DataPortal_Update() // in parent

{

//write data access code to update parent object

// then update child objects eg. Child.Update(this);

}

Within the Child.Update() write code for deleting/inserting/updating child objects.

Csla ProjectTracker application example provided with Csla downloads have sample code for this if you want to refer to.

Hope this helps.

Mary

 

 

 

Copyright (c) Marimer LLC