我有一个这样构建的员工列表:
var employees = db.employees.Where(e => e.isActive == true).ToList();
var latestSales = from es in db.employee_sales.Where(x => x.returned == false);
现在我想要的是这样的结果:
int employeeId
List<DateTime> lastSaleDates
所以我尝试了这个,但是查询需要很长时间才能完成:
var result =
(from e in employees
select new EmployeeDetails
{
EmployeeId = e.employeeId,
LastSaleDates =
(from lsd in latestSales.Where(x => x.EmployeeId == e.EmployeeId)
.Select(x => x.SaleDate)
select lsd).ToList()
};
以上工作,但实际上需要1分钟才能完成。
有什么更有效的方法来做到这一点?