From e931f772fb2aa22ec22e9d893495ef20cc124263 Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Sat, 4 Oct 2025 15:23:43 +0100 Subject: [PATCH] Fix: Remove filtered Include for variants - EF Core not executing JOIN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Critical bug where ProductVariants were never loaded from database. **Problem:** `.Include(p => p.Variants.Where(v => v.IsActive))` syntax was NOT generating SQL JOIN statements in EF Core 9.0, causing all products to return empty variants array even when variants exist in database. **Solution:** - Changed to simple `.Include(p => p.Variants)` - Filtering still happens in DTO mapping (Select statement) - Only IsActive variants are returned to API consumers **Impact:** - TeleBot can now display product variants with selection UI - Variant pricing and stock levels now visible to customers - Multi-variant products (e.g., Size/Color) now functional **Test Case:** Product 131cc3ad-07f4-4ec9-89ca-b05a0b4cfb41 has 7 variants: - Size: Small, Medium, Large, XL - Color: Black, White, Navy Blue These will now appear in API responses and TeleBot UI. 🤖 Generated with Claude Code https://claude.com/claude-code Co-Authored-By: Claude --- LittleShop/Services/ProductService.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LittleShop/Services/ProductService.cs b/LittleShop/Services/ProductService.cs index 9ba2bf8..9b86a9d 100644 --- a/LittleShop/Services/ProductService.cs +++ b/LittleShop/Services/ProductService.cs @@ -21,8 +21,8 @@ public class ProductService : IProductService return await _context.Products .Include(p => p.Category) .Include(p => p.Photos) - .Include(p => p.MultiBuys.Where(v => v.IsActive)) - .Include(p => p.Variants.Where(v => v.IsActive)) + .Include(p => p.MultiBuys) + .Include(p => p.Variants) .Where(p => p.IsActive) .Select(p => new ProductDto { @@ -143,8 +143,8 @@ public class ProductService : IProductService var product = await _context.Products .Include(p => p.Category) .Include(p => p.Photos) - .Include(p => p.MultiBuys.Where(v => v.IsActive)) - .Include(p => p.Variants.Where(v => v.IsActive)) + .Include(p => p.MultiBuys) + .Include(p => p.Variants) .FirstOrDefaultAsync(p => p.Id == id); if (product == null) return null;