Prefetch Entity vs EntityCollection<>

Posts   
 
    
iturner
User
Posts: 32
Joined: 07-Sep-2006
# Posted on: 11-Sep-2006 20:59:23   

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

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Sep-2006 07:19:57   

Would you please try the following?

C cInstance = new C(pk vals);
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.CEntity);
IPrefetchPathElement2 hElement = prefetchPath.Add(CEntity.PrefetchPathH);
IPrefetchPathElement2 iElement = hElement.SubPath.Add(HEntity.PrefetchPathI);
IPrefetchPathElement2 jElement = hElement.SubPath.Add(HEntity.PrefetchPathJ);

IPrefetchPathElement2 eElement = prefetchPath.Add(AEntity.PrefetchPathE);
IPrefetchPathElement2 dElement = prefetchPath.Add(AEntity.PrefetchPathD);
IPrefetchPathElement2 fElement = prefetchPath.Add(BEntity.PrefetchPathF);
IPrefetchPathElement2 gElement = fElement.SubPath.Add(FEntity.PrefetchPathG);
adapter.FetchEntity(cInstance, prefetchPath);
iturner
User
Posts: 32
Joined: 07-Sep-2006
# Posted on: 12-Sep-2006 09:43:52   

Hi Walaa,

No, that didn't make any real difference.

I'm going to try and isolate this part of my data model to test make sure the problems are not caused by any other parts.

Once that's done - and assuming the issue is still there - I'll make the schema, some initial data and the example code available to make replication of the problem more straightforward.

Cheers Ian

iturner
User
Posts: 32
Joined: 07-Sep-2006
# Posted on: 12-Sep-2006 13:06:06   

Right, I've managed to isolate the relevant part of my data model.

I now have

  • SQL 2005 Backup of the 'cut-down' database
  • LLBLGEN project
  • Test Project - incl. generated code from LLBLGENIt's about 500kb all zipped up. If anyone wants to kindly offer to help diagnose, I'll mail the bits and pieces over.

The test project demonstrates the problem. If I do a fetch using a prefetch path filtered to a single entity (whether it is using FetchEntity, or FetchEntityCollection using a RelationPredicateBucket) the extent to which the prefetch works varies depending on where abouts the fetched entity is in a hierarchy.

However, if i do a FetchEntityCollection without filtering on a single entity - the prefetch seems to work correctly with all entities that are returned.

The data model uses compound primary keys and multiple schemas so not sure if that is part of the problem.

I'm on iturner100 AT gmail.com if anybody wants to volunteer to help. Just send me a mail and i'll reply with the bits.

Any help gratefully appreciated.

Cheers Ian

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 12-Sep-2006 13:18:44   

You could send it to support AT llblgen.com and I'll have a look. However you have to add an explanation of the startpost with REAL entity names. Entity names a, b c etc. don't work, use real names. This will limit the time we've to look for the real entity names for the test.

Frans Bouma | Lead developer LLBLGen Pro
iturner
User
Posts: 32
Joined: 07-Sep-2006
# Posted on: 12-Sep-2006 13:56:59   

Hi,

I've mailed it over to the support address

Otis wrote:

However you have to add an explanation of the startpost with REAL entity names

I've documented this in the mail also.

Cheers Ian

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 12-Sep-2006 14:20:18   

Received it, thanks simple_smile Will look into it later this afternoon.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 12-Sep-2006 17:27:46   

Caused by a bug in the runtime. Fixed in next build. Workaround is to switch off parameterized prefetch paths (using adapter.ParameterisedPrefetchPathThreshold = 0; ) , as the subquery version doesn't do a subtype check, which contains the bug.

Frans Bouma | Lead developer LLBLGen Pro