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:
Thank you for your help.
1) The most efficient way kind of depends on your setup. In most scenarios, doing what you are doing now and filling the child as needed whenever the parent navigates (by way of FillByParentPrimaryKey) is actually the most efficient.
The other way, and I believe this is what you are looking for, is to pull all child records in the first query (preferably by using the FillByParent method) and then filter the view down to only show the child records that belong to the current row of the parent BO. This will be a bigger performance hit up front, but will be much faster from that point forward, and should only require one query. The parent child relationship can actually do the filtering for you via the ChildAutoFilterOption property on the parent business object. Just set the property to CurrentRow on the parent business object and it should filter the view of the child down for you whenever you change the current row of the parent BO.
2) The FillByParent method is used exactly the way you described (call it on the child BO and pass it the parent BO), but there may be some misunderstanding as to what it does. Using FillByParent will fill the child BO with all child records that belong to any parent record currently in the parent BO. From there you would still need to filter the child BO down to only show those records that apply to the current parent BO (which can, again, be done automatically via the ChildAutoFilterOption property on the parent BO.) Using FillByParent will omit any child records that do not belong to any parent record currently in the parent BO and is therefore more efficient than just doing a "Select * From ChildTable" to fill the child BO.
Hope it helps