我正在评估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