所以这是原始查询
SELECT SUM(PickQty),SUM(ReqQty),AssignmentID,StopID 来自PickRequest GROUP BY AssignmentID,StopID
LINQ中的
from a in dbReqs
group a by new { a.AssignmentID, a.StopID }
into pr
select new
{
Assignment = pr.Key,
StopID = pr.Select(s=> s.StopID),
PickQty = pr.Sum(p=> p.PickedQty),
Count = pr.Sum(c => c.ReqQty)
}
我必须做错事,因为LINQ版本需要很长时间,而且结果似乎有些偏差。想法?
答案 0 :(得分:2)
尝试:
from a in dbReqs
group a by new { a.AssignmentID, a.StopID }
into pr
select new
{
AssignmentID = pr.Key.AssignmentID,
StopID = pr.Key.StopID,
PickQty = pr.Sum(p=> p.PickedQty),
Count = pr.Sum(c => c.ReqQty)
}
请注意,您可以非常轻松地监视LINQ-to-SQL的功能:
ctx.Log = Console.Out; // or some other writer