PrefetchPath and SubPath

Posts   
 
    
sbense
User
Posts: 55
Joined: 24-Jul-2007
# Posted on: 18-Sep-2007 16:17:06   

The documentation on m:n relations and prefetch paths is rather scant. Hopefully the forum can provide some of the missing details.

Assume a m:n relationship represented by 3 tables A B and C: A has a 1:n relationship with B C has 1:n relationship with B B is thus the intermediate table We have another table D D has a 1:n relationship with A

The resulting code LLBL generated code results in 4 entities: TblAEntity TblBEntity TblCEntity TblDEntity

LLBLGen nicely detects the intermediate relationship and provides a collection TblCCollectionViaTblB for the TblAEntity. So let's assume you want to load TblDEntity and include the prefect paths to retrieve related data, in particular TblC which has no direct relationship to TblD. The code(pseudo) would look something like this:

    entityD = New TblDEntity(123)
    prefetchPath = New PrefetchPath2(CType(EntityType.TblDEntity, Integer))
    prefetchPath.Add(EntityD.PrefetchPathTblA)
    prefetchPath.Add(EntityD.PrefetchPathTblCCollectionViaTblB)

    adapter.FetchEntity(entityD)

    'Accessing the collections of data is now easy from these properties
    'entityD.TblA will have a collection of TblAEntity 
    'entityD.TblCCollectionViaTblB will have a collection of TblCEntity
    'entityD.TblB will be empty as the intermediate table data is not retrieved

Alternative way using SubPath, but where is the TblC collection data

    entityD = New TblDEntity(123)
    prefetchPath = New PrefetchPath2(CType(EntityType.TblDEntity, Integer))
    prefetchPath.Add(EntityD.PrefetchPathTblA)
    prefetchPath.Add(EntityD.PrefetchPathTblB).SubPath.Add(TblC)

    adapter.FetchEntity(entityD)

    'Accessing the collections of data is now easy from these properties
    'entityD.TblA will have a collection of TblAEntity 
    'entityD.TblCCollectionViaTblB will have an empty collection of TblCEntity
    'entityD.TblB will have a collection of TblBEntity 

The question is, in the second example how do you reference the SubPath TblC collection? Where is it in terms of the property to use? I can find the individual items attached to each entity in the TblB collection -When I check entityD.TblB._contents.Items(0).TblC.AnyProperty... - data is set correctly, but the collection is not available.

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 18-Sep-2007 23:46:43   

I think is better you chose one of the ways, but If your want to continue using subpaths and still want entityD.TblCCollectionViaTblB to be available you should add prefetchPath.Add(EntityD.PrefetchPathTblCCollectionViaTblB).

sbense
User
Posts: 55
Joined: 24-Jul-2007
# Posted on: 19-Sep-2007 16:13:59   

Thank you for your response. I'll follow your suggestion.