使用group by和order by时从SQL转换为Linq

使用group by和order by时从SQL转换为Linq,sql,linq,group-by,sql-order-by,Sql,Linq,Group By,Sql Order By,是否可以将此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.pN

是否可以将此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);
但是由于我无法从select部分访问t,我不知道如何获得pName和vName

var topProds = (from t in this._entities.Transactions  
               group t by t.tProductIDF into g
               orderby g.Count() descending    
               select new { ProductIDF = g.Key , Qty= g.Sum(cc=>cc.tQty) , Vname = g.Select(cc=>cc.vName).FirstOrDefault() }).Take(3); 
你的g将每一行分组