当有 group by 和 order by 时从 SQL 转换为 Linq
是否可以将这段sql代码转换为linq?
SELECT top 3 t.tProductIDF, Count(t.tQty)as QtyBought, p.pName, v.vName
From Transactions t, Product p, Vendor v
where t.tProductIDF = p.pID and p.pdeleted = 0 and p.pVendorIDF = v.vID and v.vActive = 1
Group By t.tProductIDF, p.pName, v.vName
Order By QtyBought desc;
我目前在这里:
var topProds = (from t in this._entities.Transactions
group t by t.tProductIDF into g
orderby g.Count() descending
select new {g.Key }).Take(3);
但由于我无法从选择部分访问 t,我不知道如何获取 pName 和 vName
is it possible to transform this sql code into linq?
SELECT top 3 t.tProductIDF, Count(t.tQty)as QtyBought, p.pName, v.vName
From Transactions t, Product p, Vendor v
where t.tProductIDF = p.pID and p.pdeleted = 0 and p.pVendorIDF = v.vID and v.vActive = 1
Group By t.tProductIDF, p.pName, v.vName
Order By QtyBought desc;
i am currently here:
var topProds = (from t in this._entities.Transactions
group t by t.tProductIDF into g
orderby g.Count() descending
select new {g.Key }).Take(3);
but since i cannot access t from the select part, i do not know how i can get pName and vName
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的 g 持有组中的每一行。
Your g hold each row in group.