0
  var CJTDebTransaction = from d in db.DebtorTransactions
                                 join c in db.CarJackaTrackas on d.ProductID equals c.pkfCjtID
                                 join a in db.Agents on c.AgentID equals a.pkfAgentID
                                 join s in db.SalesReps on c.SalesRepId equals s.pkfSrID
                                 where d.TransTypeID==1 && d.Product==1
                                 select new { d.Amount, d.TransTypeID, Name=a.Name.Trim(), a.pkfAgentID,s.pkfSrID,salesrepName=s.Name} into debtRec
                                 group debtRec by new { debtRec.TransTypeID, debtRec.Name, debtRec.pkfAgentID,debtRec.salesrepName,debtRec.pkfSrID} into debtRecGroup
                                 orderby debtRecGroup.Key.Name
                                 select new 
                                 { 
                                  Sum= debtRecGroup.Sum(model=>model.Amount),
                                  TransTypeId=debtRecGroup.Key.TransTypeID ,
                                  AgentId=debtRecGroup.Key.pkfAgentID,
                                  AgentName=debtRecGroup.Key.Name,
                                  SalesrepId=debtRecGroup.Key.pkfSrID,
                                  SalesRepName=debtRecGroup.Key.salesrepName 
                                 };



            var WntyDebTransaction = from d in db.DebtorTransactions
                                     join w in db.Warranties on d.ProductID equals w.Id
                                     join a in db.Agents on w.fldAgentID equals a.pkfAgentID
                                     join s in db.SalesReps on w.fldSrId  equals s.pkfSrID
                                     where d.TransTypeID == 1 && d.Product == 0
                                     select new { d.Amount, d.TransTypeID, Name=a.Name.Trim(), a.pkfAgentID, s.pkfSrID, salesrepName = s.Name } into debtRec
                                     group debtRec by new { debtRec.TransTypeID, debtRec.Name, debtRec.pkfAgentID, debtRec.salesrepName, debtRec.pkfSrID } into debtRecGroup
                                     orderby debtRecGroup.Key.Name
                                     select new
                                     {
                                         Sum = debtRecGroup.Sum(model => model.Amount),
                                         TransTypeId = debtRecGroup.Key.TransTypeID,
                                         AgentId = debtRecGroup.Key.pkfAgentID,
                                         AgentName = debtRecGroup.Key.Name.Trim(),
                                         SalesrepId = debtRecGroup.Key.pkfSrID,
                                         SalesRepName = debtRecGroup.Key.salesrepName 
                                     }

我需要在一个查询中获得输出,我是 linq to entity 的新手。我需要这样的结果:- AgentName SalesRepName 借方总计(Product == 0 的总金额)Credit Total(Product == 1 的总金额)未偿总计(借方总计和贷方总计之间的差异)。任何建议都将是可观的。提前致谢 :)

4

0 回答 0