我想在IQueryable中加入两个实体
这就是我所做的:
IQueryable<EmployeeSchedule> employeeScheduleResult =
from empSched in ctx.EmployeeSchedules.ToList()
join emp in ctx.Employees.ToList() on empSched.EmployeeId equals emp.EmployeeId
select new {
empSched.ScheduleId,
empSched.ScheduleDt,
empSched.Branch,
empSched.StartTime,
empSched.EndTime,
empSched.LunchTime,
empSched.LunchBreak,
empSched.LunchBreak_NS,
Employee = emp.LastName + emp.FirstName + emp.MiddleName
};
这是我收到的错误:
无法将类型"System.Collections.Generic.IEnumerable"隐式转换为"System.Linq.IQueryable"。存在显式转换(您是否缺少强制转换?
该错误与 Join-子句无关。您之所以获得此信息,是因为您要求查询返回EmployeeSchedule
集合,但在选择中创建了匿名类型。更改您的选择以返回新EmployeeSchedules
:
select new EmployeeSchedule
{
ScheduleId = empSched.ScheduleId,
ScheduleDt = empSched.ScheduleDt,
[...and so on..]
};