c# - Linking two lists efficiently -
i have 2 lists:
- products
- a list of product , warehouse combination containing prices/quantities etc.
two seperate results of sql queries.
the second list has 'productid'.
what i'm doing is:
foreach(var product in products) var productwarehouses = warehouses.where(x=> x.productid == productid).tolist(); product.warehouses = productwarehouses;
thing is, takes very, long.
note: i've tried splitting products chunks of lists , using parallel.foreach() , tasks take time down - still takes long.
use join
rather doing linear search through entirety of 1 collection each item in other collection:
var query = product in products join warehouse in warehouses on product.productid equals warehouse.productid warehouses select new { product, warehouses, };
Comments
Post a Comment