Automatically include related entities in relation without prefetch?

Posts   
 
    
jwoschanko
User
Posts: 1
Joined: 28-Nov-2011
# Posted on: 28-Nov-2011 22:00:01   

Say I have an LLBLGen GetMulti expression using Related entities:

Dim customers as New CustomerCollection

dim ordersRel as New RelationCollection
ordersRel.Add(CustomerEntity.Relations.OrderEntityByOrderID)

customers.GetMulti(OrderFields.TotalCost > 100, Nothing, Nothing, ordersRel)

Is it possible for the generated GetMulti query to include all matching Order entities as well as the Customer in the result set (such that, in this example, any CustomerEntities returned automatically have their "Orders" property populated with the matching orders without doing any lazy loading), without using a PrefetchPath? I'd rather not have to duplicate all the relations and logic in the relations with corresponding prefetchpaths as well, especially since PrefetchPaths seem to be overly difficult and unintuitive to put together compared to Relations.

Right now, looking at the query generated, it does Customers JOIN Orders, but the select only returns the fields from Customers. It seems like it would be kind of silly to do the join to reference all tables, but only provide the data from the first table.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Nov-2011 03:04:10   

jwoschanko wrote:

Is it possible for the generated GetMulti query to include all matching Order entities as well as the Customer in the result set (such that, in this example, any CustomerEntities returned automatically have their "Orders" property populated with the matching orders without doing any lazy loading), without using a PrefetchPath?

Hi there. That's not possible. You have to specify it yourself as those are different concepts (Relations and prefetchPaths). You can have a complex relations chain and no prefetchPath, and a lot of prefetchPaths without using relations. Relations are used when you want to filter/sort on related entities.

So, if you want something like what you are suggesting, you can write a custom method in your CustomerCollection:

Public  Class CustomerCollection
{
     ' ...

     Public Function GetMultiWithOrdersGreaterThan100() As Boolean
    {       
          Dim ordersRel as New RelationCollection
          ordersRel.Add(CustomerEntity.Relations.OrderEntityByOrderID)

          Dim path as New PrefetchPath(EntityType.Customer)
          path.Add(CustomerEntity.PrefetchPathOrders)

          this.GetMulti(OrderFields.TotalCost > 100, path, Nothing, ordersRel)
    }
}

jwoschanko wrote:

I'd rather not have to duplicate all the relations and logic in the relations with corresponding prefetchpaths as well, especially since PrefetchPaths seem to be overly difficult and unintuitive to put together compared to Relations.

Really? frowning It's easy an intuitive once you get used to it. Maybe this post could help you on that: http://www.llblgening.com/archive/2009/10/prefetchpaths-in-depth/

David Elizondo | LLBLGen Support Team