Otis wrote:
Do this self join in code by creating an EntityRelation object manually and by specifying the s and ss aliasses.
How do you specify which alias to use in the where clause?
DepartmentEmployeeCollection departmentEmployees = new DepartmentEmployeeCollection();
EntityRelation selfRelation = new EntityRelation(DepartmentEmployeeFields.EmployeeId, DepartmentEmployeeFields.EmployeeId,RelationType.OneToMany);
RelationCollection relation = new RelationCollection();
relation.Add(selfRelation, "a");
relation.Add(EmployeeEntity.Relations.DepartmentEmployeeEntityUsingEmployeeId);
PredicateExpression filter = new PredicateExpression();
***filter.Add(DepartmentEmployeeFields.DepartmentId == CurrentDepartment);
filter.Add(EmployeeFields.Active == 1);
Adding the filter I flagged with the *** causes the where to contain DepartmentEmployee.DeparmentId = 25. What I really need is to use the "a" alias in the where like a.DepartmentId = 25
The above code returns something like this:
SELECT DISTINCT <fields...>
FROM DepartmentEmployee LPA_a1
INNER JOIN DepartmentEmployee ON LPA_a1.EmployeeID=DepartmentEmployee.EmployeeID
INNER JOIN Employee ON Employee.EmployeeID=DepartmentEmployee.EmployeeID
WHERE DepartmentEmployee.DepartmentID = 25
AND Employee.Active = 1
I need it to look like this or some code that will give me this:
SELECT DISTINCT <fields...>
FROM DepartmentEmployee LPA_a1
INNER JOIN DepartmentEmployee ON LPA_a1.EmployeeID=DepartmentEmployee.EmployeeID
INNER JOIN Employee ON Employee.EmployeeID=DepartmentEmployee.EmployeeID
WHERE LPA_a1.DepartmentID = 25
AND Employee.Active = 1