문제

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?

도움이 되었습니까?

해결책

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();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top