I need to run a LINQ on a generic collection.
The current query runs at a really slow pace...
var patternsWithMaxLenArray = totalPatterns
.Where
(
pattern => pattern.Contains(maxLen) &&
pattern.All(lenInPattern => curQuantities.Keys.Contains(lenInPattern)) &&
pattern.GroupBy(len => len).All(g => g.Count() <= curQuantities[g.Key])
)
.Select(pattern => new { pattern = pattern, sum = pattern.Sum() })
.ToArray();
var patternsWithMaxLen = patternsWithMaxLenArray
.OrderByDescending(patternsum => patternsum.sum)
.Select(patternsum => patternsum.pattern);
var iq = patternsWithMaxLen.First();