0

I have the following Linq (lambda) expression:

public IEnumerable<SetupShift> GetEmployeeShift(int employeeId)
        {
            var shifts = DbContext.Set<Employee>()
                .Include(em=> em.SetupShiftCode.SetupShifts)
                .Where(em=> em.EmployeeId == employeeId)
                .Select(em => em.SetupShiftCode.SetupShifts).ToList();

            return shifts;
        }

An Employee has a ShiftCode (description), and a ShiftCode has many SetupShifts (collection of days with Intimes, etc).

I want to return only SetupShifts but when I mouse over ToList(); the result is List<ICollection<SetupShifts>> instead of only List<SetupShifts>.

Any clue?

1 Answer 1

0

Use SelectMany instead of Select.

var shifts = DbContext.Set<Employee>()
            .Include(em=> em.SetupShiftCode.SetupShifts)
            .Where(em=> em.EmployeeId == employeeId)
            .SelectMany(em => em.SetupShiftCode.SetupShifts).ToList();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.