Eager loading with ormlite servicestack

Viewed 814

This is entity framework:

var department = _context.Departments
                .Include(dep => dep.Employees.Select(emp => emp.ContactTypes))
                .SingleOrDefault(d => d.Id == departmentId);

Here I expect one department to be returned containing all related employees and all contact types for each employee.

This is ormlite servicestack:

I have no idea. When I look at the docu/samples: https://github.com/ServiceStack/ServiceStack.OrmLite

They write:

Right now the Expression support can satisfy most simple queries with a strong-typed API. For anything more complex (e.g. queries with table joins) you can still easily fall back to raw SQL queries as seen below.

I have seen there is a JoinSqlBuilder class but I do not think it can return nested collections.

Maybe what I want is not possible but maybe I can do a compromise like get all employees for the departmentId. Then I inmemory foreach the employees and fetch all contact types for a certain employeeId. Creating the hierarchy and assigning the lists would still be my job.

But I hope there is a shorter solution.

What would also be fine is when the query however it might look like return an object (Dynamic?) with 3 flat properties: Department, Employees, ContactTypes and assign thoese properties to my DTO.

1 Answers
Related