More than one prefetch on same table

Posts   
 
    
Jackk100
User
Posts: 48
Joined: 11-Jan-2005
# Posted on: 04-Jun-2007 23:28:44   

I have some code I'm trying to migrate from LLBL 1.x to 2.x. When I run it in 2.x I get this error message:

"The PrefetchPathElement you to tried to add is already added to this PrefetchPath. Parameter name: elementToAdd"

Here's the code that worked in 1.x The part that is causing the error is the very last block of code, where I'm trying to add two subpaths to the responsePath. The two subpaths have to query the same table, but do so using different relations and filters on tables. In other words, they have to be able to return the combination of two sets of results from the SurveyResponseAnswers table. One set resulting from matrixLocationFilter and matrixLocationRelations and the other set resulting from itemLocationFilter and itemLocationRelations. In both cases, the tables being joined via the relations are where the constraints are applied (ie, SurveyMatrixSetFields.SurveyQuestionTypeID == questionTypes in one case and SurveyItemFields.SurveyQuestionTypeID == questionTypes in the other case.

I've tried quite a few variations, but all have led to the same error message. Any ideas on how this can work in LLBL 2?



IPrefetchPathElement2 mapPath = prefetchPath.Add(MailboxItemEntity.PrefetchPathProposalMailboxItemMap);

IPrefetchPathElement2 proposalPath = mapPath.SubPath.Add(ProposalMailboxItemMapEntity.PrefetchPathProposal);
proposalPath.SubPath.Add(ProposalEntity.PrefetchPathSurveyForm);

// matrix-based and survey item-based event dates
//
IRelationCollection matrixLocationRelations = new RelationCollection();
matrixLocationRelations.Add(SurveyResponseAnswersEntity.Relations.SurveyMatrixSetEntityUsingMatrixSetID);

IPredicateExpression matrixLocationFilter = new PredicateExpression();
matrixLocationFilter.Add(SurveyMatrixSetFields.SurveyQuestionTypeID == questionTypes);

// survey item-based event dates
//
IRelationCollection itemLocationRelations = new RelationCollection();
itemLocationRelations.Add(SurveyResponseAnswersEntity.Relations.SurveyItemEntityUsingItemID);

IPredicateExpression itemLocationFilter = new PredicateExpression();
itemLocationFilter.Add(SurveyItemFields.SurveyQuestionTypeID == questionTypes);

// this is weird, but works in LLBL 1.x: two subpaths get data from SurveyResponseAnswers table, using different filters
//
IPrefetchPathElement2 responsePath = proposalPath.SubPath.Add(ProposalEntity.PrefetchPathSurveyResponse);

responsePath.SubPath.Add(SurveyResponseEntity.PrefetchPathSurveyResponseAnswers, 0, matrixLocationFilter, matrixLocationRelations);

responsePath.SubPath.Add(SurveyResponseEntity.PrefetchPathSurveyResponseAnswers, 0, itemLocationFilter, itemLocationRelations);


Thanks, Jack

Jackk100
User
Posts: 48
Joined: 11-Jan-2005
# Posted on: 05-Jun-2007 02:15:52   

FWIW, I worked around my issue this way:



IPredicateExpression matrixSetIDFilter = new PredicateExpression();
matrixSetIDFilter.Add(
    new FieldCompareSetPredicate( 
        SurveyResponseAnswersFields.MatrixSetID, 
        null, 
        SurveyMatrixSetFields.SetID, 
        null, 
        SetOperator.In, 
        (SurveyMatrixSetFields.SurveyQuestionTypeID == questionTypes) 
    )
);

IPredicateExpression itemIDFilter = new PredicateExpression();
itemIDFilter.Add(
    new FieldCompareSetPredicate(
        SurveyResponseAnswersFields.ItemID,
        null,
        SurveyItemFields.ItemID,
        null, 
        SetOperator.In,
        (SurveyItemFields.SurveyQuestionTypeID == questionTypes)
    )
);

IPredicateExpression ansFilter = new PredicateExpression();
ansFilter.Add(matrixSetIDFilter);
ansFilter.AddWithOr(itemIDFilter);

IPrefetchPathElement2 responsePath = proposalPath.SubPath.Add(ProposalEntity.PrefetchPathSurveyResponse);
responsePath.SubPath.Add(SurveyResponseEntity.PrefetchPathSurveyResponseAnswers, 0, ansFilter);


That seems a little clunky, but worked. I'd still like to know if there's a direct way to do what I originally had working in 1.x, though. Maybe some property I can set to allow two subpaths at the same level or something....resulting in an append?

Thanks, Jack

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Jun-2007 07:41:47   

You can only use subPath of a given prefetchPath once. The workaround using IPrefetchPathElement is ok wink Here is an expanation of complex PrefetchPaths for v2.0 http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=9264

David Elizondo | LLBLGen Support Team