2013-07-22 72 views
1

我試圖按優先級對我的門票進行分組,並計算出解決這些分組優先級內每張門票的平均時間。我不知道如何去取得預測的平均值。我如何着手在我的投影中插入平均公式,這實際上是由minElapse決定的票數。它說minElapse不在當前的情況下。正在分組和使用讓我們對如何使用變量minElapse感到困惑。由於LINQ - 使用分組進行投影並設置本地變量

var results = from r in Tickets 
where r.Team.Equals("ABC") && DateCreated >1330001100 && r.DateCreated<1350000000 //unix time 
let minElapse = r.FinishDate - r.DateCreated 
group r by r.priority into u 
select new { 
    Priority = u.Key, 
TicketCount = u.Count(), 
AverageMin = u.Average(c => minElapse) 
}; 

回答

1

你可以只是使它不使用let

var results = from r in Tickets 
where r.Team.Equals("ABC") && r.DateCreated>1330001100 && r.DateCreated<1350000000 
group r by r.priority into u 
select new 
{ 
    Priority = u.Key, 
    TicketCount = u.Count(), 
    AverageMin = u.Average(x => x.FinishDate - x.DateCreated) 
};