Complex Prefetching

Posts   
 
    
JohnRead
User
Posts: 10
Joined: 31-Jan-2005
# Posted on: 07-Nov-2005 12:27:28   

I have read the documentation and searched this forum and haven’t found a solution to this prefetch.

The tables are:

"Person" has many “PersonActivity”s. "PersonActivity" has many “Deployment”s and one "PersonActivityType".

I want to prefetch all these where the PersonActivity is not older than 6 months.

I have the following code which does not run – How do I prefetch two entities of an entity which is already prefetched?

Dim objActivityFilter As IPredicateExpression = New PredicateExpression objActivityFilter.Add(PredicateFactory.CompareValue(PERSONACTIVITYFieldIndex.PAC_END_DATE, ComparisonOperator.GreaterEqual, dtmToday.AddMonths(-6)))

Dim prefetch As PrefetchPath prefetch = New PrefetchPath(Convert.ToInt32(EntityType.PERSONEntity))

prefetch.Add(PERSONEntity.PrefetchPathPERSONACTIVITY, Integer.MaxValue, objActivityFilter).SubPath.Add(PERSONACTIVITYEntity.PrefetchPathPERSONACTIVITYTYPE) prefetch.Add(PERSONEntity.PrefetchPathPERSONACTIVITY, Integer.MaxValue, objActivityFilter).SubPath.Add(PERSONACTIVITYEntity.PrefetchPathDEPLOYMENT)

LLBL complains that I have already added the PERSONEntity.PrefetchPathPERSONACTIVITY prefetch

Thanks

John

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 07-Nov-2005 14:35:07   

Use the Predicate filters with the following prefetch paths code:

Dim prefetch As PrefetchPath
prefetch = New PrefetchPath(CType(EntityType.OrderEntity, Integer))

Dim prefetchPathElement As IPrefetchPathElement2 
prefetchPathElement = PERSONEntity.PrefetchPathPERSONACTIVITY

prefetchPathElement.SubPath.Add(PERSONACTIVITYEntity.PrefetchPathPERSONACTIVITYTYPE)
prefetchPathElement.SubPath.Add(PERSONACTIVITYEntity.PrefetchPathDEPLOYMENT)

prefetch.prefetch.Add(prefetchPathElement, Integer.MaxValue, objActivityFilter)
JohnRead
User
Posts: 10
Joined: 31-Jan-2005
# Posted on: 07-Nov-2005 15:43:10   

That worked perfectly. I think it would be useful to add such an example of using PrefecthPathElements to the documentation.

Thanks

John