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 

i want to convert this query into Linq to Entity but can't ... can some convert this query into Linq to entity for me plz

This is what I've tried:

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 };

But i don't get any output

2
  • 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 }; Commented Oct 10, 2013 at 8:25
  • i have tried this ...but i don't get any output...plz help me Commented Oct 10, 2013 at 8:26

2 Answers 2

1

To match your SQL query you'll need to group by the same columns:

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)
}
Sign up to request clarification or add additional context in comments.

Comments

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 };

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.