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
select new
{
ProductName = p.Field
BrandName = p.Field
ProductCategory = t.Field
TaxCharge = t.Field
}).ToList();
Regards
Shehzad
Anupam MaitiPosted Jan 26, 2023, 6:18 PM
Let's try your query by using AsParallel() extension method to make the query run in parallel. However, this method can only be used when the source sequence is of type IEnumerable or IQueryable
Here is the updated code for you.
NOTE : If you feel that still it is not working properly, you can try below options
Exmaple of using HashSet.
Hope this will help you.
Shehzad KhanPosted Feb 2, 2023, 5:48 PM
Hi All,
I am now stuck at HashSet compound column search.
I have attach sample program wtih sample data.
--
var result = firstTable.AsEnumerable()("ID"), Code = r.Field("CODE") })))("ID"), Name = r.Field("Name") }).ToList() ;
.Where(r => secondTableKeys.Contains(((compondkey) new compondkey { ID = r.Field
.Select(r => new { ID = r.Field
--
Shehzad KhanPosted Feb 2, 2023, 3:09 AM
Hi Anupam Maiti,
HashSet is showing more than 50% improvement in test query with test data.
However now my challenge will be to work with compund columns check in HashSet.
Thanks for sharing!
Regards
Shehzad
Shehzad KhanPosted Jan 30, 2023, 1:58 AM
Hi Sachin Singh,
As mentioned, This query is a part of existing program/design and my challenge is to optimize this query.
Or Any other approach to join in memory datatables with better performance.
Thanks,
Sachin SinghPosted Jan 27, 2023, 12:51 PM
That is the reason i prefer Dapper over EF. However you can call stored procedure with EF too. So, any specific reason of not using SPs?
Shehzad KhanPosted Jan 27, 2023, 9:25 AM
Hi @Anupam Maiti,
Thanks for example,
HashSet is getting records from one datatable only.
I will be needing data from both datatables, is there possiblity to get records from both data tables during HashSet approach
Anupam MaitiPosted Jan 27, 2023, 4:58 AM
Example added in Original response.
DONT FORGET TO ACCEPT MY ANSWER , IF IT WORKS FOR YOU.
Shehzad KhanPosted Jan 27, 2023, 1:45 AM
Hi @Anupam Maiti
Thanks for sharing, can also provide a example for below
--
Instead of joining two DataTables, if you can create a HashSet of one DataTable and
use it to lookup values in the second DataTable.
This can be faster than a join operation, especially when the second DataTable is small.
--
Hi @Jayraj Chhaya
Thanks for sharing, Let me explore
Jayraj ChhayaPosted Jan 26, 2023, 2:01 PM
You also have to add an index in Tax Id, ProductName, BrandName, ProductCategory, and TaxCharge.