Prefetch with Inheritance

Posts   
 
    
can1
User
Posts: 77
Joined: 16-Sep-2005
# Posted on: 05-Jan-2006 03:43:21   

Hello,

I am trying to layout a prefetch graph with inheritance and can't quite figure out the inheritance portion. It seems that I am trying to create a prefetch path with 2 root nodes.

I have the following graph:

QuestionSet (related 1:N) with Question

Question (as supertype to 2 sub-types): TextQuestion and OptionQuestion.

OptionQuestion (related m:1) with OptionSet.

So, I start my prefetchpath with QuestionSet, then form the prefetch to Question, no problem. The Question collection returns a collection of TextQuestion or OptionQuestion objects.

How do I specify that I also want OptionQuestion objects to prefetch out to OptionSet? The Question entity does not contain a QuestionEntity.PreFetchPathOptionQuestion where I could then do a subpath.add(OptionQuestion.PreFetchPathOptionSet).

Essentially, I can prefetch down to the question entity, but can't figure out how to tell it to prefetch from OptionQuestion to OptionSet for those Question entities that are type OptionQuestion?

Hope this explanation makes sense. Any suggestion would be greatly appreciated, as I have not been able to find any references to this issue on the forum as of yet?

Thanks,

Can1

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Jan-2006 06:27:43   

The following was copied from LLBLGen Pro documentation "Using the generated code - Adapter- Prefetch paths"

Polymorphic Prefetch Paths Because inheritance would be quite useless if polymorphism wouldn't be possible, LLBLGen Pro supports polymorphism in prefetch path technology as well. Polymorphic prefetch paths work the same as normal prefetch paths, only now they work on subtypes as well. Say you have the following hierarchy: Employee - Manager - BoardMember and BoardMember has a relation with CompanyCar (which can be a hierarchy of its own). If you then fetch all employees (which can be of type BoardMember) and you want to load for each BoardMember loaded in that fetch also its related CompanyCar, you define the prefetch path as you'd expect:

// C#
IPrefetchPath2 prefetchPath = new PrefetchPath2((int)EntityType.EmployeeEntity);
EntityCollection employees = new EntityCollection(new EmployeeEntityFactory());
// specify the actual path: BoardMember - CompanyCar
prefetchPath.Add(BoardMemberEntity.PrefetchPathCompanyCar);
// .. fetch code

So only using the prefetchPath OptionQuestion.PreFetchPathOptionSet will do the trick without the need of QuestionEntity.PreFetchPathOptionQuestion.

can1
User
Posts: 77
Joined: 16-Sep-2005
# Posted on: 05-Jan-2006 15:43:55   

Walaa,

I read that portion of the documentation, but was trying to add the prefetch to the root prefetch object, like the example you list, but my prefetch root is not the supertype of the hierarchy. This was resulting in an error: "The prefetch path element at index 2 in the passed in prefetch path for root entity type 14 is meant for root entity type 23 which isn't a subtype of 14"

I see that I have to add it to the appropriate node, in this case, the Question node which is the second node down in my hierarchy.

Thanks.

Can1