Hi,
I'm having trouble with a fetch query. I need to join onto a table twice, to get the data I need. I am using custom relations, because they do not exist in the database.
Heres the SQL that I want (slightly modified):
select dpvr.*
from maintable dpvr, performance_cache pc, performance_cache pc2
where dpvr.view_id=9
and dpvr.parent_id = pc.record_id
and pc.record_type='audit'
and pc.site_id = 264
and [b]dpvr.record_id = pc2.record_id[/b]
and pc2.record_type='section'
and pc2.site_id=264
order by pc.bandingzone desc, pc2.bandingzone desc
I thought this would be OK in LLBLGen, so I added the code, thinking that all I needed to do was make sure I set alias names for the 2 relationships to force it to join to Performance_Cache twice. But, this does not work. Heres the LLBL magic:
IEntityRelation customRelation = new EntityRelation(RelationType.OneToOne);
customRelation.AddEntityFieldPair(EntityFieldFactory.Create(MainTable.Parent_ID),
EntityFieldFactory.Create(Performance_CacheFieldIndex.Record_ID));
IEntityRelation customRelation2 = new EntityRelation(RelationType.OneToOne);
customRelation2.AddEntityFieldPair(EntityFieldFactory.Create(MainTable.Record_ID),
EntityFieldFactory.Create(Performance_CacheFieldIndex.Record_ID));
// This should add the relationship twice, with a different alias for the table to join onto.
bucket.Relations.Add(customRelation, "pc", JoinHint.Inner);
bucket.Relations.Add(customRelation2, "pc2", JoinHint.Inner);
// The rest of the filtering...
bucket.PredicateExpression.Add(PredicateFactory.CompareValue(Performance_CacheFieldIndex.Record_Type, ComparisonOperator.Equal, "AUDIT", "pc"));
bucket.PredicateExpression.Add(PredicateFactory.CompareValue(Performance_CacheFieldIndex.Group_ID, ComparisonOperator.Equal, groupSort, "pc"));
bucket.PredicateExpression.Add(PredicateFactory.CompareValue(Performance_CacheFieldIndex.Record_Type, ComparisonOperator.Equal,
"SECTION", "pc2"));
.. rest of predicate filters ..
sorter = new SortExpression();
sorter.Add(SortClauseFactory.Create(Performance_CacheFieldIndex.BandingZone, SortOperator.Ascending, "pc"));
sorter.Add(SortClauseFactory.Create(Performance_CacheFieldIndex.BandingZone, SortOperator.Ascending, "pc2"));
But this isn't working
The sorting and predicate filters part work fine, but its the joining onto teh same table twice that seems to catch LLBL out. The "aliasEndEntity" that I set when I add the relationships to the bucket should as far as I am aware allow me to do this...
Can anyone help me?
Thanks
Matt