0
  select sr.Name as Sale_Rep,ag.Name as Agent ,
         sum(tr.Amount) Debit_tran 
  from DebtorTransactions as tr 
       join Warranty as wr on tr.ProductID=wr.Id 
       join Agents as ag on ag.pkfAgentID=wr.fldAgentID 
       join SalesReps as sr on wr.fldSrId =sr.pkfSrID 
  where tr.Product=0  
  group by ag.Name, sr.Name 

このクエリを Linq から Entity に変換したいのですが、できません ... このクエリを Linq からエンティティに変換できますか plz

これは私が試したことです:

var abc= from tr in db.DebtorTransactions 
         from wr in db.Warranties 
         from sr in db.SalesReps 
         from ag in db.Agents 
         where tr.ProductID==wr.Id 
            && ag.pkfAgentID==wr.fldAgentID 
            && wr.fldSrId ==sr.pkfSrID 
            && tr.Product==0 
         select new { ag.Name, sr.Name, tr.Amount };

しかし、私は出力を得ません

4

2 に答える 2

1

SQL クエリと一致させるには、同じ列でグループ化する必要があります。

from tr in db.DebtorTransactions 
join wr in db.Warranties on tr.ProductID equals wr.Id
join ag in db.Agents on wr.fldAgentID equals ag.pkfAgentID
join sr in db.SalesReps on wr.fldSrId equals sr.pkfSrID 
group tr 
    by new { Sale_Rep = sr.Name, Agent = ag.Name }
    into transactions
select new {
    transactions.Key.Sale_Rep,
    transactions.Key.Agent,
    Debit_tran = transactions.Sum(tr => tr.Amount)
}
于 2013-10-11T10:29:46.157 に答える
0
var abc = from tr in db.DebtorTransactions 
          join wr in db.Warranties tr.ProductID equals wr.Id
          join sr in db.SalesReps wr.fldSrId equals sr.pkfSrID 
          join ag in db.Agents wr.fldAgentID equals ag.pkfAgentID
          where tr.Product==0 
          select new { ag.Name, sr.Name, tr.Amount };
于 2013-10-10T18:31:10.267 に答える