I have hierarchy setup where the last/third level is linked back to both the parent and the grandparent. I'm trying to get the prefetch to return just the entities that match the parent and grandparent but instead I end up with the entities that match just the parent. I am using self servicing LLBLGen v2.6 on SQL Server 2005.
An example of the hierarchy achieved through linking tables on both Strategy->Goal and Activity->Strategy/Goal is:
Goal1
-Strategy1
--Activity1 (Linked to Strategy1 and Goal1)
Goal1
-Strategy2
--Activity2 (Linked to Strategy2 and Goal1)
Instead both activities are getting prefetched under the strategy thus:
Goal1
-Strategy1
--Activity1
--Activity2
Goal1
-Strategy2
--Activity1
--Activity2
Basically I need to tell the prefetch that fetches the Activity collection to merge/etc on both the StrategyId and GoalId.
Tables are as follows:
Goal->GoalStrategy->Strategy->StrategyActivity (PK of 3 fields: GoalId, StrategyId, ActivityId)->Activity
The below code is what I have so far. I've played around with different filters/relations/etc in the prefetch but have not yet figured out what the trick is.
GoalCollection goals = new GoalCollection();
IPredicateExpression goalFilter = new PredicateExpression(GoalFields.EntityId == entityId);
IPrefetchPath prefetchPath = new PrefetchPath((int)EntityType.GoalEntity);
prefetchPath.Add(GoalEntity.PrefetchPathStrategyCollectionViaGoalStrategy).SubPath.Add( StrategyEntity.PrefetchPathActivityCollectionViaStrategyActivity);
//Not really being used but....
RelationCollection relationsToUse = new RelationCollection();
relationsToUse.Add(GoalEntity.Relations.GoalStrategyEntityUsingGoalId);
relationsToUse.Add(GoalEntity.Relations.StrategyActivityEntityUsingGoalId);
relationsToUse.Add(GoalStrategyEntity.Relations.StrategyEntityUsingStrategyId);
relationsToUse.Add(StrategyEntity.Relations.StrategyActivityEntityUsingStrategyId);
relationsToUse.Add(StrategyActivityEntity.Relations.ActivityEntityUsingActivityId);
goals.GetMulti(goalFilter, 0, null, relationsToUse, prefetchPath);