|
Division -> Department -> Employee
I'm sort of surprised that your query at the top level has to do anything more than exclude Inactive Divisions; but since you've said you need
1) Active divisions that have only active departments with active employees
I'm going to take your word for it for the moment. I'm just mentioning it up front in case you may be overcomplicating your problem because of not knowing how to get the filtered lists of children.
In fact, let's deal with the simpler case first, because I think the answer to that is really what you need, even if the queries at each level have to be more complicated. Suppose your problem is this:
1. You want to see only active Divisions; 2. For an active Division, you want to see only the active Departments (if there are any); and 3. For an active Department, you want to see only the active Employees (if there are any).
For the first level, your retrieval operation is something like this:
RdbQuery anRbdQuery = new RdbQuery(typeof(Division), Division.RecordStatusEntityColumn,RdbQueryOp.EQ, "Active"); EntityList<Division> activeDivisions = PM.GetEntities<Division>(anRdbQuery);
For the second level: the Departments property for a given Division is simply not going to return a filtered list unless you override its definition in your Division developer class. Assuming you don't want to do that, you can get what you need as follows:
Create a separate EntityList, departmentsForCurrentDivision or whatever, for the filtered list, and simply use an appropriate query to retrieve the needed children into it:
Division currentDivision = (Division)mDivisionsBS.Current; RdbQuery departmentRdbQuery = new RdbQuery(typeof(Department)); departmentRdbQuery.AddClause(Department.DivisionIdEntityColumn, RdbQueryOp.EQ, currentDivision.Id); departmentRdbQuery.AddClause(Department.RecordStatusEntityColumn, RdbQueryOp.EQ, "Active"); EntityList<Department> departmentsForCurrentDivision = PM.GetEntities<Department>(departmentRdbQuery);
Bind your controls to the Departments in departmentsForCurrentDivision rather than to those in currentDivision.Departments.
Note that you will need to run the above query whenever you move to a different Division, to obtain the list of its active Departments. I typically do that sort of thing in a handler for the CurrentChanged event of the parent entity's BindingSource.
Even easier (if it's an option that's open to you), you can also immortalize the above in a custom property that you add to your Division class: call it ActiveDepartments or some such. Then you can bind to currentDivision.ActiveDepartments.
For level three and on down a chain of relations of any length: Just do more of the same, filtering the list of each entity's children by excluding the Inactive ones.
If you really do want
Active divisions that have active departments with active employees
as distinguished from
Active divisions that may or may not have active departments that may or may not have active employees
(which is what I just defined the logic for) then your queries at each level will be a little more involved, requiring subqueries. But you seem already to know how to write those. Just understand that a query with subqueries still only filters the target entity: it doesn't do anything to that entity's children or other descendants, other than look at them to decide how to filter the parent list.
Best regards,
Greg Dunn
IdeaBlade
|