Fix: Remove filtered Include for variants - EF Core not executing JOIN
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 <noreply@anthropic.com>
This commit is contained in:
parent
bbf2764af9
commit
e931f772fb
@ -21,8 +21,8 @@ public class ProductService : IProductService
|
|||||||
return await _context.Products
|
return await _context.Products
|
||||||
.Include(p => p.Category)
|
.Include(p => p.Category)
|
||||||
.Include(p => p.Photos)
|
.Include(p => p.Photos)
|
||||||
.Include(p => p.MultiBuys.Where(v => v.IsActive))
|
.Include(p => p.MultiBuys)
|
||||||
.Include(p => p.Variants.Where(v => v.IsActive))
|
.Include(p => p.Variants)
|
||||||
.Where(p => p.IsActive)
|
.Where(p => p.IsActive)
|
||||||
.Select(p => new ProductDto
|
.Select(p => new ProductDto
|
||||||
{
|
{
|
||||||
@ -143,8 +143,8 @@ public class ProductService : IProductService
|
|||||||
var product = await _context.Products
|
var product = await _context.Products
|
||||||
.Include(p => p.Category)
|
.Include(p => p.Category)
|
||||||
.Include(p => p.Photos)
|
.Include(p => p.Photos)
|
||||||
.Include(p => p.MultiBuys.Where(v => v.IsActive))
|
.Include(p => p.MultiBuys)
|
||||||
.Include(p => p.Variants.Where(v => v.IsActive))
|
.Include(p => p.Variants)
|
||||||
.FirstOrDefaultAsync(p => p.Id == id);
|
.FirstOrDefaultAsync(p => p.Id == id);
|
||||||
|
|
||||||
if (product == null) return null;
|
if (product == null) return null;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user