StrataFrame Forum

How to instantiate Child Object

http://forum.strataframe.net/Topic30936.aspx

By Ger Cannoll - 2/20/2012

I have the following code in my Parent BusinessObject Vlaidation  to ensure that at least one Child is entered.... works fine from my main Parent/Child data entry form

ChildBO myChildBO = (ChildBO)this.ChildBusinessObjects[0];

if (myChildBO.Count <= 0)  { this.AddBrokenRule(this.ITR_CUSREF, "There must be at least one Detail Line"); }

 

Now , on a different form, where I am updating just one field from the Parent Business object, the MyParent.Save() gives an index error, probably because the Child BO is not instantiated. On this partcular form , the Child BI is not used at all.

How do I 'Instantiate' and populate the child Business Object in Code , so that the error does not happen

(I have tried the folloiwng code, but not quite sure what it does...got from another thread)

 

BusinessParentRelationship myRel = new BusinessParentRelationship();
myRel.ForeignKeyField = new string[] { "IDE_ITRPK" };
myRel.ParentPrimaryKeyField = new string[] {"ITR_PK"};
myRel.ParentBusinessObjectType = "ITR";
ChildBO1.ParentRelationship = myRel;
ChildBO1.IdeFillByItrpk(itrBO1.ITR_PK);

 

By Edhy Rijo - 2/20/2012

Hi Gerard,

Ger Cannoll (2/20/2012)
How do I 'Instantiate' and populate the child Business Object in Code , so that the error does not happen 

Instead of trying to create a child bo that do not exist, modify your code to test if the ChildBusinessObjects.Count > 0
By Ger Cannoll - 2/20/2012

Hi Edhy. Thanks for replying.

That has done the trick....many thanks

Regards,

Gerard

By Edhy Rijo - 2/20/2012

You are welcome Gerard.