C
C#2y ago
pauleq

❔ Need help with a linq query

Hello, why does this query return nothing List<Product> failedOrders = ( from order in orderData from warehouse in warehouseData from product in warehouse.Products where product.ProductName == order.OrderName && product.Price <= order.PriceLimit && product.Quantity >= order.OrderQuantity select new Product(product.ProductName, product.Quantity, product.Price) ).GroupBy(p => p.ProductName) .Where(g => g.Sum(p => p.Quantity) < ( from o in orderData where o.OrderName == g.Key select o.OrderQuantity ).First()) .SelectMany(g => g) .ToList();
5 Replies
trunksvn
trunksvn2y ago
maybe on this: from order in orderData from warehouse in warehouseData from product in warehouse.Products where
JakenVeina
JakenVeina2y ago
product.ProductName == order.OrderName
product.ProductName == order.OrderName
Omnissiah
Omnissiah2y ago
did you mean to do from..join..join instead of from..from..from?
VirgilReality
VirgilReality2y ago
This seems logically off: "where product.ProductName == order.OrderName " Why would a product's Name and an order's Name be the same value? I don't know how your data is organized, but I'd expect an OrderItem table to join Order and Product on IDs. Find your primary keys for those tables, and you'll have your answer.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server