2011-12-24 23 views
2

にすると、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); 

しかし、私は、選択部分からトンにアクセスできないため、私ははpNameとVNAME

答えて

1
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); 

あなたグラムを得ることができる方法がわかりませんグループ内の各行を保持します。

関連する問題