0

this is a sample join between two datatable by LINQ

 var JoinResult = (from p in dt.AsEnumerable()  
                   join t in dtTax.AsEnumerable()  
                   on p.Field<int>("Tax Id") equals t.Field<int>("Tax Id")  
                   select new  
                   {  
                       ProductName = p.Field<string>("Product Name"),  
                       BrandName = p.Field<string>("Brand Name"),  
                       ProductCategory = t.Field<string>("Product Category"),  
                       TaxCharge = t.Field<int>("Charge")   
                   }).ToList(); 

some time there could be huge amount of data in two datatable and some time two datatable has small amount of data. when data is small amount then AsParallel() not require because i know AsParallel() will slow down when run for small amount of data but when data volume is big then AsParallel() works good & fast.

please tell me how could i use AsParallel() dynamically as a result when data volume will be large and same way AsParallel() will not be applied when data volume will be small.

How to build dynamic query with expression tree for PLINQ

i found no good solution for my scenario to attach AsParallel() with my linq query dynamically. please share the know to achieve my goal. thanks

2 Answers 2

1

Just make two execution branches, one of which uses AsParallel().

if (hugeAmountOfData)
{
    result = (
                 ...
                 query.AsParallel()
                 ...
             ).ToList();
}
else
{
    result = (
                 ...
                 query
                 ...
             ).ToList();
}
Sign up to request clarification or add additional context in comments.

Comments

1

Honestly I don't think it's possible. LINQ and PLINQ have different operators. LINQ operators operate on IEnumerable<T>s, while PLINQ operators operate on ParallelQuery<T>s. So although the two versions of the query (with and without AsParallel) look exactly identical, they are fundamentally two completely different queries.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.