Shehzad Khan

Shehzad Khan

  • 1.6k
  • 159
  • 6.6k

How to Optimize Join of Two DataTables Using LINQ In C#

Jan 26 2023 9:48 AM

Hi All,

Currently query is working fine but during high volume data it is taking hours and

I need to optimize this query only (Means cannot park the code in sql command)

Example query :

//joining Product and Tax DataTable   
  
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(); 

 

Regards

Shehzad


Answers (9)