From 3505799d8d5b1c5c79f1d42bd0685a6013b1c6f0 Mon Sep 17 00:00:00 2001 From: Oleg Zhuk Date: Mon, 5 Aug 2024 09:11:24 +0200 Subject: [PATCH] VCST-1383: Fix QuerySplittingBehavior.SingleQuery Warning in Pricing (#209) fix: Fix QuerySplittingBehavior.SingleQuery Warning in Pricing --- .../Repositories/PricingRepositoryImpl.cs | 11 ++++++++--- .../Services/PricingEvaluatorService.cs | 10 ++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/VirtoCommerce.PricingModule.Data/Repositories/PricingRepositoryImpl.cs b/src/VirtoCommerce.PricingModule.Data/Repositories/PricingRepositoryImpl.cs index ef5aee1b..1859b639 100644 --- a/src/VirtoCommerce.PricingModule.Data/Repositories/PricingRepositoryImpl.cs +++ b/src/VirtoCommerce.PricingModule.Data/Repositories/PricingRepositoryImpl.cs @@ -23,7 +23,10 @@ public PricingRepositoryImpl(PricingDbContext dbContext, IUnitOfWork unitOfWork public virtual async Task> GetPricesByIdsAsync(IList priceIds) { - var result = await Prices.Include(x => x.Pricelist).Where(x => priceIds.Contains(x.Id)).ToListAsync(); + var result = await Prices + .Include(x => x.Pricelist).AsSingleQuery() + .Where(x => priceIds.Contains(x.Id)) + .ToListAsync(); return result; } @@ -34,7 +37,7 @@ public virtual async Task> GetPricelistByIdsAsync(IList x.Assignments); + query = query.Include(x => x.Assignments).AsSplitQuery(); } var result = await query.Where(x => pricelistIds.Contains(x.Id)) @@ -44,7 +47,9 @@ public virtual async Task> GetPricelistByIdsAsync(IList> GetPricelistAssignmentsByIdAsync(IList assignmentsId) { - var result = await PricelistAssignments.Include(x => x.Pricelist).Where(x => assignmentsId.Contains(x.Id)).ToListAsync(); + var result = await PricelistAssignments + .Include(x => x.Pricelist).AsSingleQuery() + .Where(x => assignmentsId.Contains(x.Id)).ToListAsync(); return result; } diff --git a/src/VirtoCommerce.PricingModule.Data/Services/PricingEvaluatorService.cs b/src/VirtoCommerce.PricingModule.Data/Services/PricingEvaluatorService.cs index 13852c64..428235cf 100644 --- a/src/VirtoCommerce.PricingModule.Data/Services/PricingEvaluatorService.cs +++ b/src/VirtoCommerce.PricingModule.Data/Services/PricingEvaluatorService.cs @@ -138,7 +138,8 @@ public virtual async Task GetAllPricelistAssignments() { repository.DisableChangesTracking(); - return (await repository.PricelistAssignments.Include(x => x.Pricelist).AsNoTracking().ToListAsync()) + return (await repository.PricelistAssignments + .Include(x => x.Pricelist).AsSingleQuery().AsNoTracking().ToListAsync()) .Select(x => x.ToModel(AbstractTypeFactory.TryCreateInstance())).ToArray(); } } @@ -159,9 +160,10 @@ public virtual async Task> EvaluateProductPricesAsync(PriceEvaluati using (var repository = _repositoryFactory()) { //Get a price range satisfying by passing context - var query = (repository).Prices.Include(x => x.Pricelist) - .Where(x => evalContext.ProductIds.Contains(x.ProductId)) - .Where(x => evalContext.Quantity >= x.MinQuantity || evalContext.Quantity == 0); + var query = (repository).Prices + .Include(x => x.Pricelist).AsSingleQuery() + .Where(x => evalContext.ProductIds.Contains(x.ProductId)) + .Where(x => evalContext.Quantity >= x.MinQuantity || evalContext.Quantity == 0); if (evalContext.PricelistIds.IsNullOrEmpty()) {