Reputation: 135
I'm new with LINQ and I need help Converting this SQL Code: To LINQ
SELECT UserId_FK,COUNT(OrderId),SUM(Quantity)
FROM Orders o
JOIN OrderDetails od
ON(o.OrderId = od.OrderId_FK)
GROUP BY UserId_FK;
Upvotes: 1
Views: 139
Reputation: 4992
Without seeing your schema file, I'm going to take a guess here:
var userDetail =
context.Orders
.GroupBy(i => i.UserId_Fk)
.Select(i => new {
UserId_Fk = i.Key,
OrderCount = i.Count(),
ProductQuantity = i.Sum(j => context.OrderDetails.Where(k=> k.OrderId_Fk == j.OrderId).Sum(k=> k.Quantity))
});
Upvotes: 3