Explain Prefetch Paths

Posts   
 
    
wayne avatar
wayne
User
Posts: 611
Joined: 07-Apr-2004
# Posted on: 17-Sep-2005 01:07:33   

Hi All.

I have never bothered with these prefetch paths but wish to know how it works. The manual has the following example:

' VB.NET
Dim orders As New OrderCollection()
Dim prefetchPath As IPrefetchPath = New PrefetchPath(CType(EntityType.OrderEntity, Integer))
prefetchPath.Add(OrderEntity.PrefetchPathCustomer)
Dim filter As IPredicateExpression = New PredicateExpression()
filter.Add(PredicateFactory.CompareValue(OrderFieldIndex.EmployeeId, ComparisonOperator.Equal, 2))
orders.GetMulti(filter, prefetchPath)

I run the code and viewed with the profiler. I can see that 2 queries are generated - Just as the manual says. The first query i can understand - Filter Orders to only return orders for Emp 2. But where does the 2nd query's (Customers) data go? And how do i access it as i can only see a collection of orders.

Does it mean that if i do orders(1).Customers() after the prefetch LLBLGen won't make a query to find the customers because it already knows it?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 17-Sep-2005 02:15:22   

Correct. After defining a prefetch path the corresponding entities are filled when the source entity is fetch. So any call to Orders(1).Customer will not result in a another query, but use the customer that is already in memory.

Fishy avatar
Fishy
User
Posts: 392
Joined: 15-Apr-2004
# Posted on: 17-Sep-2005 17:36:24   

wayne wrote:

Does it mean that if i do orders(1).Customers() after the prefetch LLBLGen won't make a query to find the customers because it already knows it?

Just to clarify the last part of your question. llbl won't generate a query regardless if it knows it or not. You have to do a prefetch or load customers manually.