Fix: Apply variant loading workaround to GetProductByIdAsync

This commit is contained in:
SysAdmin 2025-10-05 16:55:20 +01:00
parent 7dbdc0d46f
commit 0e8b53df01

View File

@ -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,