Prefetch several layers deep

Posts   
 
    
ajwalters
User
Posts: 4
Joined: 11-Oct-2006
# Posted on: 05-Apr-2007 00:34:44   

LLBLGen Pro Version: 1.0.2005.1 Final Database: SQL 2005

My question concerns preforming multiple prefetch steps when retrieving a collection from the database. Allow me to explain:

ApplicationEntity relates to EmployeeEntity, so I can prefect the Employee of the Application and later access the employee via ApplicationEntity.Employee.

SSNEntity relates to the EmployeeEntity, so if prefetch is preformed, i can do EmployeeEntity.SSN to access the SSN attributes of this employee.

IS there any way i can execute two prefetchs, so taht when i retrieve my ApplicationEntity collection, the related employee will already have the related SSN entity retrieved?

The code i have to retrieve the application entities with employees prefetched is below:

IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.ApplicationEntity); prefetchPath.Add(ApplicationEntity.PrefetchPathEmployee);

EntityCollection applicationCol = new EntityCollection(new ApplicationEntityFactory()); RelationPredicateBucket filter = new RelationPredicateBucket(); filter.Relations.Add(ApplicationEntity.Relations.EmployeeMasterEntityUsingEmpId);

filter.PredicateExpression.Add(PredicateFactory.Like(EmployeeMasterFieldIndex.FirstName, pmEmployeeFName + "%"));

filter.PredicateExpression.Add(PredicateFactory.Like(EmployeeMasterFieldIndex.LastName, pmEmployeeLName + "%"));

filter.PredicateExpression.Add((ApplicationFields.TsFinish != System.DBNull.Value));

filter.PredicateExpression.Add((ApplicationFields.TsInterviewFinish == System.DBNull.Value));

DataAccessAdapter da = new DataAccessAdapter(); da.FetchEntityCollection(applicationCol, filter, prefetchPath);

Thanks in advance! Adam

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Apr-2007 04:32:26   

Adam, you can use SubPath (Ref.: LLBLGenPro Help - Using generated code - Adpater - Prefetch Paths) For more complex prefetch paths, review this thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=9264

In this case you can easily use SubPath:

// add the path graph
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.ApplicationEntity);
prefetchPath.Add(ApplicationEntity.PrefetchPathEmployee)
     .SubPath.Add(EmployeeEntity.PrefetchPath.SSN);

Hope helpful.

David Elizondo | LLBLGen Support Team