From c27db06880d657b13bdaf0c12c0c682b153ede07 Mon Sep 17 00:00:00 2001 From: Dhananjaya99 <152056742+ashanruu@users.noreply.github.com> Date: Sat, 17 Oct 2026 18:24:57 +0530 Subject: [PATCH] feat: add PriceAdjustmentLine repository to PriceAdjustmentService and optimize pending item query --- .../Services/PriceAdjustmentService.cs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Backend/ERPCore/Services/PriceAdjustmentService.cs b/Backend/ERPCore/Services/PriceAdjustmentService.cs index 1984221..7837e8d 100644 --- a/Backend/ERPCore/Services/PriceAdjustmentService.cs +++ b/Backend/ERPCore/Services/PriceAdjustmentService.cs @@ -25,6 +25,7 @@ public sealed class PriceAdjustmentService : IPriceAdjustmentService public const string ApprovalNavCode = "products.price-adjustments"; private readonly IRepository _adjustments; + private readonly IRepository _lines; private readonly IRepository _items; private readonly IRepository _history; private readonly IRepository _users; @@ -36,11 +37,13 @@ public sealed class PriceAdjustmentService : IPriceAdjustmentService private readonly IUnitOfWork _uow; public PriceAdjustmentService( - IRepository adjustments, IRepository items, IRepository history, - IRepository users, IRepository config, IApprovalService approvals, - INotificationService notifications, INumberSequenceService numbers, ICurrentUser currentUser, IUnitOfWork uow) + IRepository adjustments, IRepository lines, IRepository items, + IRepository history, IRepository users, IRepository config, + IApprovalService approvals, INotificationService notifications, INumberSequenceService numbers, + ICurrentUser currentUser, IUnitOfWork uow) { _adjustments = adjustments; + _lines = lines; _items = items; _history = history; _users = users; @@ -92,10 +95,14 @@ public sealed class PriceAdjustmentService : IPriceAdjustmentService var ids = request.Lines.Select(l => l.ItemId).ToList(); var items = await _items.Query().Where(i => ids.Contains(i.ItemId)).ToDictionaryAsync(i => i.ItemId, ct); - var pendingItemIds = await _adjustments.Query().AsNoTracking() - .Where(p => p.Status == PriceAdjustmentStatus.PendingApproval || p.Status == PriceAdjustmentStatus.PendingSecondApproval) - .SelectMany(p => p.Lines.Select(l => new { l.ItemId, p.DocNo })) - .Where(x => ids.Contains(x.ItemId)) + // Queried from the line side (not PriceAdjustment.Lines via SelectMany) so this stays a + // plain join — a SelectMany over a to-many navigation generates a CROSS APPLY that + // Pomelo/MySQL can't translate (it works fine against PostgreSQL, which is what this + // predates — 2026-10-16 MySQL-port regression). + var pendingItemIds = await _lines.Query().AsNoTracking() + .Where(l => ids.Contains(l.ItemId) + && (l.PriceAdjustment!.Status == PriceAdjustmentStatus.PendingApproval || l.PriceAdjustment!.Status == PriceAdjustmentStatus.PendingSecondApproval)) + .Select(l => new { l.ItemId, DocNo = l.PriceAdjustment!.DocNo }) .ToListAsync(ct); var lines = new List();