How to accomplish a different INNER JOIN

Posts   
 
    
varalonga
User
Posts: 7
Joined: 28-Nov-2005
# Posted on: 17-Apr-2012 13:39:53   

Hi!

I'm using v2.6 and I what I want to accomplish is the equivalent to the following query:

SELECT * FROM Evaluation INNER JOIN ExamType ON Evaluation.ExamTypeId = ExamType.ExamTypeId INNER JOIN Student ON Evaluation.StudentId = Student.StudentId INNER JOIN EvaluationTest ON Evaluation.EvaluationId = EvaluationTest.EvaluationId INNER JOIN Test ON EvaluationTest.TestId = Test.TestId INNER JOIN TestItem ON Test.TestId = TestItem.TestId INNER JOIN Question ON TestItem.QuestionId = Question.QuestionId INNER JOIN Plan_ExamType ON Evaluation.PlanId = Plan_ExamType.PlanId AND Evaluation.ExamTypeId = Plan_ExamType.ExamTypeId AND

I tried the following code:

IPrefetchPath2 pp = new PrefetchPath2((int) EntityType.EvaluationEntity) { EvaluationEntity.PrefetchPathExamType, EvaluationEntity.PrefetchPathStudent }; pp.Add(EvaluationEntity.PrefetchPathEvaluationTest). SubPath.Add(EvaluationTestEntity.PrefetchPathTest). SubPath.Add(TestEntity.PrefetchPathTestItem). SubPath.Add(TestItemEntity.PrefetchPathQuestion); pp.Add(EvaluationEntity.PrefetchPathPlan). SubPath.Add(PlanEntity.PrefetchPathPlanExamType);

var evaluation = new EvaluationEntity(evaluationId); ctx.Adapter.FetchEntity(evaluation, pp);

This would be perfect, but the problem seems to lie on the last inner join. I wan the Plan_ExamType to be joined to Evaluation by the 2 fields PlanId and ExamTypeId. By fetching the PlanExamType through the PlanEntity prefetch It will only link through the PlanId field, thus retrieving unwanted records. Is there any way of forcing this kind of join (through two fields). Thanks in advance.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Apr-2012 19:39:22   

Hi there,

First of all, Relations (JOINS) are not equivalent to PrefetchPaths (additional fetchs to attach to your main collection fetch). What you are really using is PrefetchPaths, so you are fetching an evaluation and all the graph from it.

PrefetchPaths use the information of the relationships to know how to retrieve a related entity/collection. In your case the association is made only by PlanId field because the relationship says so. This behavior of PrefetchPaths can't be changed.

What you can do is fetch the desire additional collection separately, using some kind of PredicateExpression that filters the results using the data retrieved in your previous fetch, you could use FieldCompareSetPredicate for that.

David Elizondo | LLBLGen Support Team