I'm having trouble converting a C# Linq statement to VB.NET. I need the following statement converted. I am getting hung up on the i.Sum(v=>v) part.
from p in Products
from u in Users
let i = (from op in OrderProducts
where op.Order.User == u && op.Product == p
select op.ProductQty)
let quant = i.Count() == 0 ? 0 : i.Sum(v=>v)
select new {p.ProductName, u.UserName, Quantity = quant}
Here's what I have for VB, but the If(i.Count() = 0, 0, i.Sum()) _ statement says Parameterless aggregate operator 'Sum' is not supported over projections during runtime (no compile time errors). I have also tried i.Sum(Function(q) i.ProductQty) which doesn't work either (says sum cannot be called with these arguments).
From p In Products _
From u In Users _
Let i = (From op In OrderProducts _
Where op.Order.User.UserID = u.UserID And op.Product.ProductID = p.ProductID _
Select op.ProductQty) _
Let Qty = _
If(i.Count() = 0, 0, i.Sum()) _
Select New With {p.ProductName, u.Username, Qty}
Any ideas on how to get that converted to VB.NET and working? Thanks!