2009-01-15 90 views
1

因此,這裏是原始查詢SQL到L2S翻譯幫助

SELECT SUM(PickQty),SUM(ReqQty),AssignmentID,StopID FROM PickRequest GROUP BY AssignmentID,在LINQ

StopID

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版本需要很長時間,而且結果似乎有點偏離。想法?

回答

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到SQL確實很容易:

ctx.Log = Console.Out; // or some other writer