Debug: Enhanced logging for variant loading investigation

This commit is contained in:
SysAdmin 2025-10-05 17:00:04 +01:00
parent 6f4befa188
commit 45da991945

View File

@ -193,15 +193,23 @@ public class ProductService : IProductService
if (product == null) return null; if (product == null) return null;
// Manually load variants - using fresh query to avoid Contains() json_each bug in EF Core 9 + SQLite // Manually load variants - using fresh query to avoid Contains() json_each bug in EF Core 9 + SQLite
var variants = await _context.ProductVariants // Load ALL variants first to debug
.Where(v => v.ProductId == id && v.IsActive) var allVariants = await _context.ProductVariants.ToListAsync();
.OrderBy(v => v.SortOrder) Console.WriteLine($"[DEBUG GetProductById] Total variants in DB: {allVariants.Count}");
.ToListAsync(); Console.WriteLine($"[DEBUG GetProductById] Looking for ProductId: {id} (Type: {id.GetType().Name})");
Console.WriteLine($"[DEBUG GetProductById] ProductId: {id}, Variants loaded: {variants.Count}"); var matchingByProductId = allVariants.Where(v => v.ProductId == id).ToList();
Console.WriteLine($"[DEBUG GetProductById] Matching by ProductId: {matchingByProductId.Count}");
var matchingByIsActive = allVariants.Where(v => v.IsActive).ToList();
Console.WriteLine($"[DEBUG GetProductById] Matching by IsActive: {matchingByIsActive.Count}");
var variants = allVariants.Where(v => v.ProductId == id && v.IsActive).OrderBy(v => v.SortOrder).ToList();
Console.WriteLine($"[DEBUG GetProductById] Final variants loaded: {variants.Count}");
foreach (var v in variants.Take(3)) foreach (var v in variants.Take(3))
{ {
Console.WriteLine($"[DEBUG GetProductById] - {v.VariantType}: {v.Name}"); Console.WriteLine($"[DEBUG GetProductById] - {v.VariantType}: {v.Name}, ProductId: {v.ProductId}");
} }
return new ProductDto return new ProductDto