Prefetch path & related entities

Posts   
 
    
sgay
User
Posts: 53
Joined: 23-Nov-2006
# Posted on: 04-Jun-2007 20:19:10   

Can not find out how to do this:

Suppose EntityA -> EntityB (1:n)

EntityA has a field (say, AvgLevel) and EntityB has a field (say, Level).

I want to fetch some EntityAs, and for each EntityA, prefetch those EntityBs that have EntityB.EntityAId == EntityA.Id (of course), and EntityB.Level > EntityA.AvgLevel.

?

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 04-Jun-2007 21:21:21   

since your relating a to b in the filter I would recommend

PrefetchPath.Add(AEntity.PrefetechBOnId);
PrefetchPath[0].Filter.Add((BFields.level > AFields.AvgLevel));
PrefetchPath[0].FilterRelations = new EntityRelationCollection();
PrefetchPath[0].FilterRelations.Add(new ARelations.BOnId);

sgay
User
Posts: 53
Joined: 23-Nov-2006
# Posted on: 05-Jun-2007 10:08:10   

jmeckley wrote:

since your relating a to b in the filter I would recommend

PrefetchPath.Add(AEntity.PrefetechBOnId);
PrefetchPath[0].Filter.Add((BFields.level > AFields.AvgLevel));
PrefetchPath[0].FilterRelations = new EntityRelationCollection();
PrefetchPath[0].FilterRelations.Add(new ARelations.BOnId);

Using the following code:


IPrefetchPath2 pp;
IPrefetchPathElement2 ppe;

pp = new PrefetchPath2((int)EntityType.EntityA);
ppe = pp.Add(EntityA.PrefetechPathEntityBs);
ppe.Filter.Add((EntityBFields.level > EntityAFields.AvgLevel));

// following line removed, FilterRelations is readonly
//ppe.FilterRelations = new EntityRelationCollection();

// removed 'new'
ppe.FilterRelations.Add(EntityA.Relations.EntityBUsingEntityAId);

... the ASP.NET server dies (stack overflow) so it's hard to tell what's going wrong. I'll have to create a standalone app and debug through it... unless someone has a better idea?

Edited : the server dies because of code that has nothing to do w/LLBLGen, after the correct query has returned successfully. So, question considered answered. Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Jun-2007 10:18:55   

Indeed, you should debug and see what hangs it. Also you should check the generated queries to see if something was generated in a wrong way, by setting some tracing switches, please check the manual "Using the generated code -> Troubleshooting and debugging"

Also please try the following line: ppe.FilterRelations.Add(EntityB.Relations.EntityAUsing...); Instead of: ppe.FilterRelations.Add(EntityA.Relations.EntityBUsingEntityAId);

EDIT: Glad it's solved.