PrefetchPath2: Master->Child->GrandChild->Master

Posts   
 
    
Nill
User
Posts: 7
Joined: 11-Oct-2006
# Posted on: 11-Oct-2006 14:14:20   

I'm trying to fill a graph of entities. I've got the following tables/entities:

Master: MasterId 1

Child (references Master): ChildId MasterId 1 1 2 1

GrandChild (references Master and Child): GrandChildId MasterId ChildId 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 2

Is it possible to fill my entities so I can traverse from Master to Child to GrandChild to Master? I'd like the following statement to be correct: Master.Child[0].GrandChild[0].Master == Master

With this code:


  IPrefetchPath2 prefetchPath = new PrefetchPath2((int) EntityType.MasterEntity);
  prefetchPath.Add(MasterEntity.PrefetchPathChild).SubPath.Add(ChildEntity.PrefetchPathGrandChild);

I get this result:


  Master.Child.Count -> 2 //OK
  Master.GrandChild.Count -> 0 //Expected to be 6
  Master.Child[0].GrandChild.Count -> 5 //OK
  Master.Child[1].GrandChild.Count -> 1 //OK
  Master.Child[0].GrandChild[0].Master -> null //Expected to equal Master

With this code:


  IPrefetchPath2 prefetchPath = new PrefetchPath2((int) EntityType.MasterEntity);
  prefetchPath.Add(ReportMasterEntity.PrefetchPathGrandChild);
  prefetchPath.Add(ReportMasterEntity.PrefetchPathChildCollectionViaGrandChild);

I get this result:


  Master.Child.Count -> 0 //Expected to be 2
  Master.GrandChild.Count -> 6 //OK
  Master.GrandChild[0].Child -> null //Expected to be a ChildEntity

I've spent some time searching this forum for a sollution, but haven't found one.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Oct-2006 15:11:55   

Try the following:

IPrefetchPath2 prefetchPath = new PrefetchPath2((int) EntityType.MasterEntity);
prefetchPath.Add(MasterEntity.PrefetchPathChild).SubPath.Add(ChildEntity.PrefetchPathGrandChild).SubPath.Add(GrandChildEntity.PrefetchPathMaster);

Nill
User
Posts: 7
Joined: 11-Oct-2006
# Posted on: 11-Oct-2006 16:12:52   

Walaa wrote:

Try the following:

IPrefetchPath2 prefetchPath = new PrefetchPath2((int) EntityType.MasterEntity);
prefetchPath.Add(MasterEntity.PrefetchPathChild).SubPath.Add(ChildEntity.PrefetchPathGrandChild).SubPath.Add(GrandChildEntity.PrefetchPathMaster);

Unfortunately this results in my MasterEntity being loaded twice. Master and Master.Child[0].GrandChild[0].Master are two different objects.

I'm not sure if LLBLGen supports what I'm trying. But if it does, I'd really like to learn how to write the code.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 11-Oct-2006 16:25:12   

Please use a Context object with the fetch. this will make the entities be the same

Frans Bouma | Lead developer LLBLGen Pro
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Oct-2006 16:34:24   

You may want to use a Context. Please refer to the LLBLGen Pro manual: "Using the generated code -> Adapter -> Using the context"

Nill
User
Posts: 7
Joined: 11-Oct-2006
# Posted on: 12-Oct-2006 08:53:47   

Thank you guys. This did the trick. I'm still new to LLBLGen, but it seems to be a really strong O/R mapper.