Nested/hierarchical business entities?

Dec 16, 2007 at 11:56 AM
The RF is great, but I'm not really sure about nested objects...

All employees can be assigned to none, one ore many departments.

Employee (EmployeeID, LastName, FirstName, ...)
Department (DepartmentID, Name, ...)
EmployeeDepartment (EmployeeDepartmentID, EmployeeID, DepartmentID)

Employee (...) (generated)
Department (...) (generated)
EmployeeDepartment (EmployeeDepartmentID, EmployeeID, DepartmentID, Employee, Department) (extended by a partial class)

If I want to get all correlations from EmployeeDepartment for a centain DepartmentID, I'd like to call a custom stored proc GetEmployeeDepartmentByDepartmentID (which returns all columns of the three tables) and map the result to a extended version of the generated EmployeeDepartment class (which contains Employee and Department fields/properites).
Unfortunately the wizzard of the RF can only map flat objects (EmployeeName -> EmployeeName) and not nested objects (EmployeeName -> Employee.Name).

Now, what's the most elegant way to handle this?
  1. Create a facade in which all objects are loaded seperately: List<EmployeeDepartment> = GetEmployeeDepartmentByDepartmentID(...) and for every item .Employee = GetEmployeeByEmployeeID(..) and .Department = GetDepartmentByDepartmentID(...)? -> Performance could be bad...
  2. Extend the repository (inheritance) and replace the GetXxx method to use an extended factory for object creation? -> Code could become (too) complex...

Thanks in advance!