Hello,
Using the search I've found this post on the forum:
http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=16664&HighLight=1
I've the same problem, and tried the proposed solution. Here is the code:
/*
* SELECT * FROM EMPLOYEE e
* INNER JOIN (SELECT DISTINCT E_ID FROM VW_POPULATION WHERE USR_ID=70) vw ON vw.E_Id=e.E_Id
*/
// first specify the elements in the derived table select : E_ID
ResultsetFields innerJoinFields = new ResultsetFields(1);
innerJoinFields.DefineField(VwPopulationFields.EId, 0);
DerivedTableDefinition dtDefinition = new DerivedTableDefinition(
innerJoinFields, "vw",
new PredicateExpression(VwPopulationFields.UsrId == this.User.UsrId)
);
// then specify the relation.
// derivedtable spec, join type, end entity type, alias first element, alias end element, on clause filter
DynamicRelation rel = new DynamicRelation(
dtDefinition,
JoinHint.Inner,
EntityType.EmployeeEntity,
"e",
EmployeeFields.EId.SetObjectAlias("e") == VwPopulationFields.EId.SetObjectAlias("vw")
);
filter.Relations.Add(rel);
(I can't make a distinct directly on the employee table because there are ntext fields)
And this code generate the query in the wrong way (it the text from DebugVisualizer):
(
(
SELECT VwPopulationEntity.[EId] FROM VwPopulationEntity WHERE
(
VwPopulationEntity.[UsrId] = @UsrId1
)
)
LPA_v1 INNER JOIN EmployeeEntity LPA_e2 ON LPA_e2.[EId] = LPA_v1.[EId]
)
In fact I think there is no DynamicRelation CTor to create it in the correct order:
public DynamicRelation(DerivedTableDefinition leftOperand, JoinHint joinType, DerivedTableDefinition rightOperand, IPredicate onClause);
public DynamicRelation(DerivedTableDefinition leftOperand, JoinHint joinType, EntityType rightOperand, string aliasRightOperand, IPredicate onClause);
public DynamicRelation(EntityType leftOperand, JoinHint joinType, EntityType rightOperand, string aliasLeftOperand, string aliasRightOperand, IPredicate onClause);
I should have :
public DynamicRelation(EntityType leftOperand, JoinHint joinType, DerivedTableDefinition rightOperand, string aliasRightOperand, IPredicate onClause);
Is it possible to do it manually ? The property on the DynamicRelation object are read-only
Tx a lot