auto prefetch on load?

Posts   
 
    
tracstarr
User
Posts: 8
Joined: 19-Feb-2009
# Posted on: 02-Mar-2009 23:24:37   

Is it possible to have an entity automatically always prefetch when it loads? For example, can something be done within the OnInit or otherwise of an entity? The only option I know of is with the fetchentity call. I'd like to make it so that certain prefetch paths are always used no matter what fetchentity method is used.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Mar-2009 03:28:17   

Are you using Adapter templateSet right? The best solution would be have some manager classes that have methods that do this, for instance:

public CustomerEntity GetCustomer(string customerId)
{
     IPrefetchPath2 thePath = new PrefetchPath2((int) EntityType.CustomerEntity;
     path.Add(CustomerEntity.PrefetchPathOrders);

     CustomerEntity toReturn = new CustomerEntity(customerId);
     using (DataAccessAdapter adapter =new DataAccessAdapter())
     {
          adapter.FetchEntity(toReturn, thePath);
     }

     return toReturn;
}

Above solution gives you reusability and transparency. Overriding the FetchEntity and FetchEntityCollection won't work because you don't (and shouldn't) have the DBGeneric assembly referenced at DBSpecific project (where the DataAccessAdapter resides).

David Elizondo | LLBLGen Support Team
tracstarr
User
Posts: 8
Joined: 19-Feb-2009
# Posted on: 03-Mar-2009 14:29:31   

thanks. Guess I was hoping to be able to do it with entity customizations.