Newbie prefetch question

Posts   
 
    
M6rk
User
Posts: 37
Joined: 29-Sep-2004
# Posted on: 29-Sep-2004 22:41:06   

Using the "Selfservice" model:

Given the following tables, and assuming child entities are suffixed with the text "Items":

Grandparent [id] [name]

Parent [id] [grandparentId] [name]

Child [id] [parentId] [name]

How would you code to get all the Grandparent objects, prefeching all parent and all child objects with and without filtering?

Much thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 30-Sep-2004 10:02:41   

M6rk wrote:

Using the "Selfservice" model:

Given the following tables, and assuming child entities are suffixed with the text "Items":

Grandparent [id] [name]

Parent [id] [grandparentId] [name]

Child [id] [parentId] [name]

How would you code to get all the Grandparent objects, prefeching all parent and all child objects with and without filtering?


GrandparentCollection grannies = new GrandparentCollection();
IPrefetchPath prefetcher = new PrefetchPath((int)EntityType.Grandparent);
prefetcher.Add(GrandparentEntity.PrefetchPathParentItems).SubPath.Add(
    ParentEntity.PrefetchPathCHildItems);
grannies.GetMulti(null, prefetcher);

This should be it. simple_smile

It's a little hidden in hte prefetch path docs, half way on the page:

The example above is a rather simple graph, just two nodes. LLBLGen Pro's Prefetch Path functionality is capable of handling much more complex graphs and offers options to tweak the fetch actions per PrefetchPathElement2 object to your liking. To illustrate that the graph doesn't have to be linear, we'll fetch a more complex graph: a set of Customer entities, all their related Order entities, all the Order's Order Detail entities and the Customer entities' Address entities. The example illustrates how to use sublevels in the graph: use the SubPath property of the PrefetchPathElement object used to build graph nodes with.

Frans Bouma | Lead developer LLBLGen Pro
kakaiya
User
Posts: 182
Joined: 20-Mar-2004
# Posted on: 13-Jul-2006 05:31:50   

I need a code for above tables using Adapter model....

Regards,

Kaksss

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Jul-2006 07:27:23   

Corresponding Adapter code:

EntityCollection grannies = new EntityCollection(new GrandparentEntityFactory);

IPrefetchPath prefetcher = new PrefetchPath((int)EntityType.Grandparent);
prefetcher.Add(GrandparentEntity.PrefetchPathParentItems).SubPath.Add(
    ParentEntity.PrefetchPathChildItems);

DataAccessAdapter adapter = new DataAccessAdapter();
adapter.FetchEntityCollection(grannies, null, prefetcher);

kakaiya
User
Posts: 182
Joined: 20-Mar-2004
# Posted on: 13-Jul-2006 08:08:43   

Hi

What I do not understand is below code.


prefetcher.Add(GrandparentEntity.PrefetchPathParentItems).SubPath.Add(
    ParentEntity.PrefetchPathChildItems);

IF I do NOT have relationship defined in the SQL Server how can I solve this as I do NOT have "PrefetchPathParentItems" shown up in Intellisense when I type "GrandparentEntity."

Regards

Kaksss

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Jul-2006 09:12:37   

If you don't have relations defined in the database then you may define them manually using the LLBLGen Pro Designer. Please refer to LLBLGen Pro documentation "Using the designer -> Adding custom relations"

kakaiya
User
Posts: 182
Joined: 20-Mar-2004
# Posted on: 13-Jul-2006 09:56:55   

Hi,

I do NOT want to define the relationship in LLBLGen as well and I would like to create relationship in VB.NET (VS2005) and then want to use adapter code.

Please give me code example.

Regards

Kaksss

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Jul-2006 10:08:38   

You may add a relation in code, but this won't solve your prefetchPath question.

kakaiya
User
Posts: 182
Joined: 20-Mar-2004
# Posted on: 14-Jul-2006 05:11:50   

Thanks Walaa

Close this.

Regards

Kaksss