I am trying to Prefetch a 3rd level entity using PrefetchPaths.
I have the following code:
The root EntityCollecton and the adapter's fetch:
EntityCollection orderColl = new EntityCollection(new OrderEntityFactory());
...
adapter.FetchEntityCollection(orderColl, bucket, BuildPrefetchPaths());
The summarized BuildPrefetchPaths logic
private IPrefetchPath2 BuildPrefetchPaths()
{
PrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.OrderEntity);
PrefetchPathElement2 schedPrefetch = (PrefetchPathElement2)OrderEntity.PrefetchPathScheduleItem;
if (_prefetchScheduleItemEmployee)
{
schedPrefetch.SubPath.Add(ScheduleItemEntity.PrefetchPathEmployee);
}
prefetch.Add(schedPrefetch, 0, null, null, new SortExpression(ScheduleItemFields.StartDateTime | SortOperator.Ascending));
return prefetch;
}
The problem is that it does not fetch the Employee from the ScheduleItem using:
schedPrefetch.SubPath.Add(ScheduleItemEntity.PrefetchPathEmployee);
This is a m:1 relation between ScheduleItem & Employee. Watching SQL Profiler, no SQL is generated for this sub-fetch. However, if I change this to another m:1 relation (ScheduleItemEntity.PrefetchPathScheduleType) it does generate the SQL for the sub-fetch.
What would cause one m:1 SubPath prefetch to generate SQL & the other to go dormant & not generate any sql nor runtime error?