0
I have this query
qry.ForEach(q =>
            {
                var product = new Product();
                product.CategoryId = q.CategoryId;
                product.AuthorizeMaximumPercentageAlteration = q.AuthorizeMaximumPercentageAlteration;
                product.AuthorizeMinimumPercentageAlteration = q.AuthorizeMinimumPercentageAlteration;
                product.HaveMaximumPercentage = q.HaveMaximumPercentage;
                product.HaveMinimumPercentage = q.HaveMinimumPercentage;
                product.Hidden = q.Hidden;
                product.ChildrenCategoryId = q.ChildrenCategoryId;
                product.Description = q.Description;
                product.DistributionCenterErpId = q.DistributionCenterErpId;
                product.MaximumPercentage = q.MaximumPercentage;
                product.MinimumPercentage = q.MinimumPercentage;
                product.Name = q.Name;
                product.NameHtml = q.NameHtml;
                product.Order = q.Order;
                product.PartNumber = q.PartNumber;
                product.PictureId = q.PictureId;
                product.ShortDescription = q.ShortDescription;
                product.StandardMarkup = q.StandardMarkup;
                //if (product.PictureId.HasValue)
                //    q.PictureFilename = product.Picture.FileName;
                //var pct = product.PictureId.Value > 0 ? q.PictureFilename = product.Picture.FileName : "";
                var parentProducts = _productService.GetParentsOf(product.Id).Select(x => x.PartNumber);
                q.Parents.AddRange(parentProducts);
                var price = _erpPriceService.GetPrice(product, 1, resellerId).Result;
                if (price.BasePriceUSD > 0)
                    q.DolarRate = price.BasePriceBRL / price.BasePriceUSD;
                q.ResellerPriceUSD = price.ResellerPriceUSD;
                q.ResellerPriceBRL = price.ResellerPriceBRL;
                q.BasePriceBRL = price.BasePriceBRL;
                q.BasePriceUSD = price.BasePriceUSD;
            });
In this line the performance is bad
var price = _erpPriceService.GetPrice(product, 1, resellerId).Result;
This is because, as you can see, for each product item, this call is made. This call is a service, which goes to the bank takes the values of each item and returns. This is a long way. If a stride of this, take 10s, for example, in 202 items I would have 2020 seconds, which kills the execution of the entire system. You who are good at this, there is a way, parallel, asynchronous or otherwise, to minimize this impact that is very great. Any help is welcome.
What I want, to be direct, is how I outline this problem, in the line quoted, to improve performance
Need the whole object to get the price? Or just a key? I ask because I would probably be able to get the price for all products before getting into that
ForEach.– João Martins