0
나는이 linq 성명서를 가지고 있으며 심각한 성능 문제에 직면하고 있습니다. 문제는 코드의 중간에있는 .Count() 호출에 있다고 생각합니다.Count() linq 쿼리 내에서 성능 문제를 피하는 방법?
var products = from product in pm_products
join price in GetResellers().Where(x => x.Price != 0) on product.Id equals price.PM_Price.Product_Id into productPrices
let minprice = productPrices.Min(x => x.Price)
let maxprice = productPrices.Max(x => x.Price)
let difference = ((double)maxprice - (double)minprice)/(double)minprice * 100
let number = productPrices.Count()
let success = productPrices.Where(x => x.Status == PriceStatus.OKAY).Count()
let unknown = productPrices.Where(x => x.Status == PriceStatus.NONE).Count()
let fail = productPrices.Where(x => x.Status == PriceStatus.FAIL).Count()
select new Product
{
PM_Product = product,
BestPrice = minprice,
WorstPrice = maxprice,
Fail = fail,
Number = number,
Success = success,
Unknown = unknown,
Difference = difference
};
Count()가 쿼리를 실행한다는 것을 읽었지만 한 번만 실행하면됩니다. 위 공사를 기반으로 어떻게이를 달성 할 수 있습니까?
이에서 카운트를받을 수 있나요? 쿼리가 훨씬 빨라 집니까? – dasblinkenlight
글쎄, 당신은 이미 적어도 두 번 (min과 max)의'productPrices' join을 모으고 있습니다, 그래서 나는 Count 만이 그것을 책임지고 있음을 의심합니다. –
예. 그것은 1600ms에서 32ms로 변합니다. – Peter