Prefetch paths - deep fetching entities

Posts   
 
    
Posts: 30
Joined: 17-Sep-2006
# Posted on: 29-Jul-2007 16:39:07   

Hi there,

Is there any way for me to specify a two-stage prefetch? For example,

// pre-fetch for TypeEntity IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.TypeEntity); // want to load the Namespace object related to this TypeEntity // this works fine prefetchPath.Add(TypeEntity.PrefetchPathNamespace); // but also want to load the related Assembly object, related // to this Namespace. LLBLGen doesn't like this! prefetchPath.Add(NamespaceEntity.PrefetchPathAssembly); TypeEntity type = new TypeEntity(typeId); a.FetchEntity(type, prefetchPath);

Is there any way for me to do this? For the moment, I'm just executing the following query afterwards:

type.Namespace.Assembly = new AssemblyEntity(type.Namespace.AssemblyId); a.FetchEntity(type.Namespace.Assembly);

which works fine - but just thought I'd check if there was a better way.

Cheers

James

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 29-Jul-2007 17:00:43   

Yes.


// pre-fetch for TypeEntity
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.TypeEntity);
// want to load the Namespace object related to this TypeEntity
// this works fine

IPrefetchPathElement2 nodeNs = prefetchPath.Add(TypeEntity.PrefetchPathNamespace);

nodeNs.Subpath.Add(NamespaceEntity.PrefetchPathAssembly);

a.FetchEntity(type, prefetchPath);

This code isn't tested, and I assume you are using adapter. The trick is that the add method actually returns an object we often ignore. take that object and add the second prefetch to it.

I think the documentation should give an example of this if it doesn't.

Hope that helps.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Jul-2007 21:14:16   
David Elizondo | LLBLGen Support Team