Fetching Related Data After The Fact in Adapter.

Posts   
 
    
Posts: 112
Joined: 09-Aug-2004
# Posted on: 28-Jun-2005 22:50:03   

Here is our scenario:


Data
Customer -- 1:M -- Credit Cards

On the client side, we have a form (Customer Form) which opens a search form. The search form loads a list of customers. Once a customer is selected, the entity is passed back to the Customer Form. From there we display the credit cards on a grid.

Currently, when we load the data for the search screen we have a prefetch path which includes a path to the credit cards. It loads the data fine.

This solution has the possibilty to be very slow. We want to fetch just the credit cards for a customer.

Is there something built in that will do this for us? Or do we have to fetch the list manually based off of the PK of the customer?

Thanks

jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 29-Jun-2005 00:43:54   

lethologica wrote:

Here is our scenario:


Data
Customer -- 1:M -- Credit Cards

On the client side, we have a form (Customer Form) which opens a search form. The search form loads a list of customers. Once a customer is selected, the entity is passed back to the Customer Form. From there we display the credit cards on a grid.

Currently, when we load the data for the search screen we have a prefetch path which includes a path to the credit cards. It loads the data fine.

This solution has the possibilty to be very slow. We want to fetch just the credit cards for a customer.

Is there something built in that will do this for us? Or do we have to fetch the list manually based off of the PK of the customer?

Thanks

You'll need to fetch the list manually as there is no way to designate which of the Customers in the list you wish to load Credit Cards for - this would amount to some sort of conditional join.

As you don't really have a problem in Self-Servicing, I assume you're using Adapter. Probably the best solution for you is the Context object. You can find more information in the docs at "Using the generated code->Adapter->Using the context". But, basically, a context allows you to take an existing, fetched entity or graph, and fetch additional data "into" it.

So, in your case, remove the prefetch path for credit card, then, when the user chooses the customer, use the Context and fetch the credit card information INTO the selected customer. No refetches necessary and you get your complete object graph returned intact with the additional information.

Jeff...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 29-Jun-2005 12:30:29   

Thanks Jeff simple_smile

I don't think a context is really needed, as for a single entity the creditcard entities are fetched, so you can simply fetch it on the normal way: adapter.FetchEntityCollection(customer.CreditCards, customer.GerRelationInfoCreditCards());

Frans Bouma | Lead developer LLBLGen Pro
Posts: 112
Joined: 09-Aug-2004
# Posted on: 29-Jun-2005 15:01:02   

Otis,

That is exactly what I was looking for! Thanks alot! This is great. simple_smile

jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 29-Jun-2005 20:36:30   

Otis wrote:

Thanks Jeff simple_smile

I don't think a context is really needed, as for a single entity the creditcard entities are fetched, so you can simply fetch it on the normal way: adapter.FetchEntityCollection(customer.CreditCards, customer.GerRelationInfoCreditCards());

Ah, yes. My mistake. Why do something the easy way, when you can do it more complicatedly? simple_smile

Jeff...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 29-Jun-2005 20:52:10   

simple_smile Though using a prefetch path will in this case result in more queries, which might not what you want (though, it's on the edge of nittpicking, I know wink )

Frans Bouma | Lead developer LLBLGen Pro