Child Collection Population via context

Posts   
 
    
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 16-Feb-2008 18:17:57   

I'm using the latest released version of LlblGenPro 2.5

I have three tables for example Customer (CustomerId - Pk, CustomerName) Provider (ProviderId - Pk, ProviderName) Invoice (InvoiceId - Pk, CustomerId - Fk, ProviderId - Fk, Amount)

Invoice is related 1-n to Customer and to Provider.

I can fetch Invoice and prefetch all related Customer and Provider. I can also fetch all Customers and all Providers (with or without prefetching their related Invoices).

If I add these collections to the same context before fetching everything comes out ok from a relationship and child collection/ parent entity uniqueing standpoint.

However, I have extra (redundant) datafetches within the customer and provider tables since some of those have already been fetched with the prefetches on Invoice. I also have the extra work of duplicate elimination happening in the uniqueing context.

I don't think LLBLGenPro will let me instead fetch Customers, Providers, and Invoices without prefetchs, add them all to the same context and let the context resolve relationships and fill proper Child collections and parent entity variables on each entity.

Am I wrong? If I am great. If I am not, I would like to request that this feature be added or that the context object expose enough of it's innards to allow me to make this happen.

p.s. The tables/relationships described here are just samples, but in the real world situations this could be very useful.

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 16-Feb-2008 20:41:06   

Copied from manual:

If an entity is already loaded in the used Context object, the entity data is not added to a new entity object, but the entity object already loaded is updated. If the already loaded object is dirty, the data isn't updated and the loaded entity data is simply skipped, and the already loaded entity object is returned as is. This is done in the Get routine of the Context object. The Context has a flag to disallow this particular action: SetExistingEntityFieldsInGet. See the LLBLGen Pro reference manual for details on this flag.

...

Fetching an entity and using a prefetch path use either FetchUsingPK() or FetchUsingUCFieldnames(). Both have an overload which accepts a Context object. If you're fetching a graph and you want to have for every already loaded entity in a particular Context the instance in which the entity is already loaded, you can pass in the context in which these entity objects already are added to. The fetch logic will then build the object graph using the instances from the passed in Context, otherwise it will read the entity data in newly created entity objects.

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 16-Feb-2008 23:07:08   

Thanks. Yes, I'm familiar with the manual, but doesn't address what I am asking (for if it doesn't already do it). I'm asking about the relationships being connected between fetched entities while it is doing it's uniqueing.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39865
Joined: 17-Aug-2003
# Posted on: 17-Feb-2008 12:05:38   

Am I wrong? If I am great. If I am not, I would like to request that this feature be added or that the context object expose enough of it's innards to allow me to make this happen.

This isn't implemented. What you want is that you fetch a bunch of entities, say Customer, Order, OrderDetails, Employees, add them to the context and voila a graph pops out simple_smile

The drawback is: you've to specify the sets using filters, i.e. if you fetch all customers from the USA, and you want their orders to be fetched as well, you're better off with a prefetch path.

The advantage of what you propose is that if you have a set of customers and some orders, and you want to merge them, you can hand that over to a class and it's done for you.

What this needs is a graph governing class, which uses a context. The context isn't a graph manager, it's just a bucket which hands out unique objects.

We have plans to implement a graph manager/governing class in v3, together with undo/redo and transactional graph management, and this is then a small addition to it. Opening up the context isn't planned for v2.6, as time is short.

Frans Bouma | Lead developer LLBLGen Pro
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 17-Feb-2008 12:31:50   

I look forward to v3