I'm assessing a performance issue in my C# .NET web application and have traced the bottleneck to a chained lambda expression. I would like to remove the lambda expression entirely so I can evaluate the performance of each step in the chain however I am relatively new to lambda expressions. Does anyone have any thoughts on how the second lambda express could be refactored into more traditional code so that each step or action can traced?
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 });**
ToDictionaryand theGroupBy? TheToDictionarywould appear unnecessary.