我试着写一个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);
当我运行这个,然后尝试迭代的结果,我得到一个错误说"指定的方法是不支持的"。
有人知道为什么吗?我该怎么解决这个问题?
我猜是三级?:操作符不能转换为SQL
对于按2列分组,您需要GroupBy(x => new {x.DateOfProduction, x.Worker});
。你能解释一下你需要什么吗,因为你的linq对我来说太难了。