Hi,
I'm experiencing a slight problem with Prefetch Paths when trying to retrieve my entities. I'll describe the entity structure quickly first:
Entity A, B and C in a Target-Per-Entity-Hierarchy (A is root; B is sub-type of A and so on)
Entity D relates to A (1:1)
Entity E related to A (n:1)
Entity F related to B (1:n)
Entity G related to F (1:n - optional)
Entity H related to C (1:n)
Entity I related to H (1:n)
Entity J related to H (1:n)
Entities A & B are both marked as abstract.
I want to get a single instance of entity C with all the related entities prefetched at the same time.
So, my code looks something like this:
C cInstance = new C(pk vals);
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.CEntity);
IPrefetchPathElement2 eElement = prefetchPath.Add(CEntity.PrefetchPathE);
IPrefetchPathElement2 dElement = prefetchPath.Add(CEntity.PrefetchPathD);
IPrefetchPathElement2 hElement = prefetchPath.Add(CEntity.PrefetchPathH);
IPrefetchPathElement2 iElement = hElement.SubPath.Add(HEntity.PrefetchPathI);
IPrefetchPathElement2 jElement = hElement.SubPath.Add(HEntity.PrefetchPathJ);
IPrefetchPathElement2 fElement = prefetchPath.Add(CEntity.PrefetchPathF);
IPrefetchPathElement2 gElement = fElement.SubPath.Add(FEntity.PrefetchPathG);
adapter.FetchEntity(cInstance, prefetchPath);
This, however, doesn't bring back any of the entities that are related to the super-types of C - i.e. doesn't fetch D, E, F or G.
It seems that whatever I use as the root type of the path (in this case CEntity) restricts the prefetch - i.e. i'm not getting the polymorphic fetching that i would like.
However, if i use the exact same prefetch path, but this time fetch an EntityCollection<CEntity> it does fetch all of the related entities as hoped for.
Code for that would be:
EntityCollection<CEntity> cInstances = new EntityCollection<CEntity>(new CEntityFactory());
RelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.PredicateExpression.Add(...);
IPrefetchPath prefetchPath = ... same as before
adapter.FetchEntityCollection(cInstances, bucket, prefetchPath);
So, I feel like I must be missing something obvious about fetching just the single entity - but not sure what!
Any help would be greatly appreciated.
Cheers
Ian