From 0e8b53df0152b5b821ed56ffe232179f3f399949 Mon Sep 17 00:00:00 2001 From: SysAdmin Date: Sun, 5 Oct 2025 16:55:20 +0100 Subject: [PATCH] Fix: Apply variant loading workaround to GetProductByIdAsync --- LittleShop/Services/ProductService.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/LittleShop/Services/ProductService.cs b/LittleShop/Services/ProductService.cs index 93de65d..2e52be4 100644 --- a/LittleShop/Services/ProductService.cs +++ b/LittleShop/Services/ProductService.cs @@ -188,11 +188,16 @@ public class ProductService : IProductService .Include(p => p.Category) .Include(p => p.Photos) .Include(p => p.MultiBuys) - .Include(p => p.Variants) .FirstOrDefaultAsync(p => p.Id == id); if (product == null) return null; + // Manually load variants - using fresh query to avoid Contains() json_each bug in EF Core 9 + SQLite + var variants = await _context.ProductVariants + .Where(v => v.ProductId == id && v.IsActive) + .OrderBy(v => v.SortOrder) + .ToListAsync(); + return new ProductDto { Id = product.Id, @@ -231,7 +236,7 @@ public class ProductService : IProductService CreatedAt = v.CreatedAt, UpdatedAt = v.UpdatedAt }).ToList(), - Variants = product.Variants.OrderBy(v => v.SortOrder).Select(v => new ProductVariantDto + Variants = variants.Select(v => new ProductVariantDto { Id = v.Id, ProductId = v.ProductId,