Skip to content

Commit

Permalink
VP-4972: Fix SearchPrices with GroupByProducts=true flag (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Egis authored Oct 12, 2020
1 parent 07c9104 commit 15b33c6
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,23 @@ public virtual Task<PriceSearchResult> SearchPricesAsync(PricesSearchCriteria cr

if (criteria.GroupByProducts)
{
var groupedQuery = query.GroupBy(x => x.ProductId).OrderBy(x => 1);
var groupedQuery = query.Select(x => x.ProductId).OrderBy(x => x).Distinct();
result.TotalCount = await groupedQuery.CountAsync();
query = groupedQuery.Skip(criteria.Skip).Take(criteria.Take).SelectMany(x => x);

if (criteria.Take > 0)
{
query = query.Where(x => groupedQuery.Contains(x.ProductId));
}
}
else
{
result.TotalCount = await query.CountAsync();
query = query.Skip(criteria.Skip).Take(criteria.Take);
}

if (criteria.Take > 0)
{
var priceIds = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id)
.Skip(criteria.Skip).Take(criteria.Take)
.Select(x => x.Id)
.AsNoTracking()
.ToArrayAsync();
Expand Down

0 comments on commit 15b33c6

Please sign in to comment.