我正在評估C#.NET Web應用程序中的性能問題,並將瓶頸追蹤到鏈式lambda表達式。我想完全刪除lambda表達式,所以我可以評估鏈中每個步驟的性能,但我對lambda表達式相對較新。有沒有人對如何將第二個lambda表達式重構爲更傳統的代碼有任何想法,以便每個步驟或動作都可以跟蹤?消除.net lambda表達式
IEnumerable<OurPerformance> validPerformances = package.TimeFilteredValidPerformances(visitDateAndTime);
IEnumerable<WebPerformance> webPerformances = performanceGroup.RegularNonPassedPerformances
.Where(performance => validPerformances.Select(perf => perf.PerformanceId).Contains(performance.PerformanceId))
.Select(performance =>
new WebPerformance
{
Date = performance.PerformanceDate.ToJavaScriptDateString(),
PerformanceId = performance.PerformanceId,
Title = performance.UserFriendlyTitle,
ProductionSeasonId = performance.ProductionSeasonId,
AvailableCount = performance.AvailableCount
});
**IEnumerable<WebProduction> webProductions = webPerformances
.GroupBy(performance => performance.ProductionSeasonId)
.ToDictionary(grouping => SheddProduction.GetOurProduction(grouping.Key), grouping => grouping.ToList())
.Select(perfsByProduction =>
new WebProduction
{
ProductionSeasonId = perfsByProduction.Key.ProductionSeasonNumber,
Duration = perfsByProduction.Key.Duration,
Title = perfsByProduction.Key.UserFriendlyTitle,
Synopsis = perfsByProduction.Key.UserFriendlySynopsis,
ThumbnailImage = perfsByProduction.Key.PreviewImage,
Performances = perfsByProduction.Value
});**
爲什麼你要同時使用ToDictionary和GroupBy? 「ToDictionary」似乎不必要。 – dbc