我试图编写一个 LINQ 查询,它将所有详细信息集中在一个地方,我需要生产日期、员工姓名以及该员工应该为他的工作获得的总金额。这就是我到目前为止所拥有的:
var PrePerWorker =
(from Production in context.production
where Production.ProductionDate >= dtpStartDate.SelectedDate && Production.ProductionDate <= dtpEndDate.SelectedDate
select new
{
Worker =
(from Employee in context.employees
where Employee.ID == Production.EmpID
select Employee.FirstName).FirstOrDefault(),
DateOfProduction = Production.ProductionDate,
Total =
Production.Side == 1 ? Production.Amount *
(from Product in context.products
where Product.ProductID == Production.ProductID
select Product.SideA).FirstOrDefault():
Production.Side == 2 ? Production.Amount *
(from Product in context.products
where Product.ProductID == Production.ProductID
select Product.SideB).FirstOrDefault():
Production.Side == 3 ? Production.Amount *
(from Product in context.products
where Product.ProductID == Production.ProductID
select Product.SideC).FirstOrDefault(): 0
}).GroupBy(x => x.DateOfProduction, x => x.Worker);
当我运行它然后尝试迭代结果时,我收到一条错误消息,提示“不支持指定的方法”。
有谁知道为什么?我该如何解决这个问题?