This question is locked. New answers and comments are not allowed.
Hi all,
I have a working code, but I its extremely slow and needs to be optimized. But Im not sure where to do this optimization. I have three tables:
When I display my product grid, i need data from all these tables.. here is what I do:
This seems to take about 10 seconds for displaying 8 products. If I comment out the query for pricelist and gallery, its fast.
One solution would be to use Joins. But I would like to know how to do it in OpenAccess.
Another solution would be to remove the Gallery table and bring smallImage and bigImage to Products table.
Can anybody guide me to the right direction?
I have a working code, but I its extremely slow and needs to be optimized. But Im not sure where to do this optimization. I have three tables:
- Products -> Holding general information
- PriceList -> Holding details of price for each configuration of a product
- ProductGallery -> Holding urls of images of a product
When I display my product grid, i need data from all these tables.. here is what I do:
var plist = dbContext.Products.Where(x => x.Category == cid && x.To_display == true);
foreach (Product prod in plist)
{
ProductDM temp = new ProductDM();
temp.ProductName = prod.Name_en;
temp.ProductID = prod.Product_id;
temp.Detail = prod.Detail_en;
var prlist = dbContext.PriceLists.Where(x => x.Product_id == prod.Product_id);
temp.PriceList = new Hashtable();
foreach (PriceList pl in prlist)
{
temp.PriceList.Add(pl.Specification, pl.Unit_price);
}
var pimgs = dbContext.ProductGalleries.FirstOrDefault(x => x.Product_id == prod.Product_id);
temp.SmallImage = pimgs.Summary;
temp.BigImage = pimgs.Image1;
productList.Add(temp);
}
This seems to take about 10 seconds for displaying 8 products. If I comment out the query for pricelist and gallery, its fast.
One solution would be to use Joins. But I would like to know how to do it in OpenAccess.
Another solution would be to remove the Gallery table and bring smallImage and bigImage to Products table.
Can anybody guide me to the right direction?