Get PrefetchPaths based on loaded entities

Posts   
 
    
RMarietta
User
Posts: 5
Joined: 23-May-2012
# Posted on: 23-May-2012 22:31:43   

Is it possible to get the prefetch paths needed to eager load an entity based on what another instance of that entity already has loaded?

Here's an example of what I'm trying to do: 1. Receive a request to update a customer (from a web page or service) 2. Instantiate a new instance of CustomerEntity with the information (everything is new on the instance) 3. Before saving the customer information, get the customer information from the database in order to determine what the deltas are.

Step #3 is where I need to determine how deep to load the customer (using prefetchpath). I don't want to load all of the customer's phones, contacts, etc if the only thing updated was the customer's name. I figure if I can interrogate the entity built in step #2 in order to find out what is being updated (using GetMemberEntityCollections()) I could use that to interrogate the relationships on the entity in order to get the prefetchpaths I need in order to eager load the right amount of data.

using... LLBLGen Pro v3.5 (4/20/12) VS2010/.NET 4.0 LLBLGen framework with adapter model

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-May-2012 22:58:14   

You ate not using a bindingSource or a dataSource, are you? Anyway you can check a related entity, if it's dirty, before constructing the relevant prefetchPath.

RMarietta
User
Posts: 5
Joined: 23-May-2012
# Posted on: 24-May-2012 00:24:59   

No, I'm not using bindingSource or dataSource... I'll be receiving information from a web service (in a different format such as HR-XML) that will be used to create the entity instance. So everything is dirty.

I could write code to explicitly check the child entity collection and build a prefetchPath like this...


// contact is an entity that was built from a web service request

var collections = ((IEntity2)contact).GetMemberEntityCollections();
var prefetch = new PrefetchPath2(EntityType.ContactEntity);
foreach (var collection in collections)
{
    if (collection[0].GetType() == typeof(ContactPhoneEntity))
    {
        prefetch.Add(ContactEntity.PrefetchPathPhones);
    }

    if (collection[0].GetType() == typeof(ContactCustEntity))
    {
        prefetch.Add(ContactEntity.PrefetchPathCustomers);
    }
}

but I was hoping there was a more abstract way to get the prefetches using GetMemberEntityCollections() against the base classes/interfaces that didn't require maintenance as additional relationships are added.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-May-2012 06:54:18   

How do you guarantee that data in he database was not changed since the last time you have read them? Also there might be some database triggered updates to the fields. Gneerally speaking, the best practice is to fetch everything after the save.

Otherwise you'll need to do the check manually as you showed.