Accessing Children BOs from a Parent BO Programmatically


Author
Message
Leonard P.
Leonard P.
StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)
Group: Awaiting Activation
Posts: 65, Visits: 306
Hello,

I have what seems to be a very simple scenario, but for whatever reason can't get it to work correctly.

I defined parent/child relationship between 2 BOs; 1) setup ParentRelationShip property in BO designer by PK_Id to FK_Id and 2) Dropped 2 objects on the form and set ParentObject property.

I want to loop through parent objects and inner loop children of each parent. But I am getting all "Children" objects for each parent, instead of true children as defined by IDs. What am I missing?

Also is there way to get strongly typed Child object from parent instead of: parentBO.ChildBusinessObjects[0];

here's relevant code:

private void PopulateFactSheets()
{
FillFactSheetsObjects();
if (factSheetCategory.MoveFirst())
{
do
{
TreeNode fsTypeNode = trvFactSheets.Nodes.Add(factSheetCategory.FactSheetType);
FactSheetReport fsR = (FactSheetReport)factSheetCategory.ChildBusinessObjects[0];//can I get to strongly typed child?
if (fsR.MoveFirst())
{
do
{
fsTypeNode.Nodes.Add(fsR.IndexName);
} while (fsR.MoveNext());
}
} while (factSheetCategory.MoveNext());
}
}
private void FillFactSheetsObjects()
{
SqlCommand sqlCmnd = new SqlCommand(SqlCommands.SelectAllFactSheets + ";" + SqlCommands.SelectFactSheetTypes);
BusinessLayer.FillMultipleDataTables(sqlCmnd, factSheetReport, factSheetCategory);
// factSheetReport.ParentBusinessObject = factSheetCategory; //it's set in the designer
}

Thank you for your help.


Reply
Leonard P.
Leonard P.
StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)StrataFrame Novice (93 reputation)
Group: Awaiting Activation
Posts: 65, Visits: 306
Hi,

Ok, I did get it to work, see codesnippet below.

I just have a few questions regarding that:

1. What's the most efficient way of getting children of each parent. I was hopping there would be a way to Fill all BOs at once and loop through parents and get children on each parent, instead of making multiple ".FillByParentPrimaryKey" calls

2. I tried using .FillByParent(parentBo) method, but it didn't work. How does this method work?

Thank you.

private void PopulateFactSheets()
{
// FillFactSheetsObjects();
factSheetCategory.FillDataTable(SqlCommands.SelectFactSheetTypes);
if (factSheetCategory.MoveFirst())
{
do
{
TreeNode fsTypeNode = trvFactSheets.Nodes.Add(factSheetCategory.FactSheetType);
// FactSheetReport fsR = (FactSheetReport)factSheetCategory.ChildBusinessObjects[0];//can I get to strongly typed child?
FactSheetReport fsR = new FactSheetReport();
fsR.FillByParentPrimaryKey(factSheetCategory.FactSheetTypeId);
if (fsR.MoveFirst())
{
do
{
fsTypeNode.Nodes.Add(fsR.IndexName);
} while (fsR.MoveNext());
}
} while (factSheetCategory.MoveNext());
}
}


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search