Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 LINQ 新手,需要帮助转换此 SQL 代码:到 LINQ
SELECT UserId_FK,COUNT(OrderId),SUM(Quantity) FROM Orders o JOIN OrderDetails od ON(o.OrderId = od.OrderId_FK) GROUP BY UserId_FK;
在没有看到您的架构文件的情况下,我将在这里猜测一下:
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)) });