If you are looking for each combination, use the SelectManyone usually executed with several from statements instead :
return from p1 in patterns1
from p2 in patterns2
let combination = p1.Concat(p2)
where combination.Sum() <= stockLen
select combination;
This is without any parallelism, though ... depending on the expected collections, I would probably just parallelize at the same level, for example.
return from p1 in patterns1.AsParallel()
from p2 in patterns2
let combination = p1.Concat(p2)
where combination.Sum() <= stockLen
select combination;
Please note that there is no guarantee regarding the order in which the results come out with the above - you need to configure it if you want to complete the initial order.
source
share