New parent object with children - persistance of child object's parent Id

New parent object with children - persistance of child object's parent Id

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


cmclernon posted on Wednesday, March 04, 2009

Hi all,

I am having a problem whereby the ParentId in a Child Object of a New Parent object is not being refreshed properly when the parent is saved.  The Parent.Id is an INT Identity column.

I am using CSLAContrib templates and initially the Child_Insert method is created as follows:

private void Child_Insert(ParentObject parent)

...

data.ParentObjectID = ReadProperty<int>(ParentObjectIDProperty);

This results in the child record being saved with a ParentObjectID of 0.  When I changed this to the following, the child record is saved correctly with the proper ParentObjectID:

data.ParentObject= parent.Id;

Is what I'm doing so far correct?  If not, please advise, but if so, do I manually need to update the ParentObjectIDProperty with the correct value after the DataContext.SubmitChanges() method is called as the ParentObject does not contain children with the proper ParentObjectID?

Thanks,

Colm

Copyright (c) Marimer LLC