日期:2014-05-20  浏览次数:20859 次

主表连子表连两次取两个值 一条linq搞定 ?
 var query = (from a in adviceNoteEarnestMoneyTableEntities.View_AdviceNoteRightTable
                     join b in adviceNoteEarnestMoneyTableEntities.AdviceNoteLinkTable.Where(x => x.PayType == 42) on a.AdviceID equals b.AdviceID
                     join c in adviceNoteEarnestMoneyTableEntities.ExitRec on b.PayReturnID equals c.ID
                     join d in adviceNoteEarnestMoneyTableEntities.ContractSubReturnPayment.Where(y => y.PayType == 4) on c.ID equals d.RPID into t
                     from d in t.DefaultIfEmpty() into g
                     select new
                     {
                         AdviceID = g.Key.AdviceID,
                         AdviceState = g.Key.AdviceState,
                         AdviceType = g.Key.AdviceType,
                         ID = g.Key.ID,
                         OutDate = g.Key.OutDate,
                         ExitRecCount = g.ExitRecCount,
                         PayMoney = g.PayMoney
                     }).OrderByDescending(s => s.AdviceID);
我想让下面这个表在连一次并且这回paytype等于7了
adviceNoteEarnestMoneyTableEntities.ContractSubReturnPayment.Where(y => y.PayType == 7) 
完事要查出分别查出paytype是等于47时的paymonery,paymonery可以起别名,要左连接
------最佳解决方案--------------------

var query = (from a in adviceNoteEarnestMoneyTableEntities.View_AdviceNoteRightTable
  join b in adviceNoteEarnestMoneyTableEntities.AdviceNoteLinkTable.Where(x => x.PayType == 42) on a.AdviceID equals b.AdviceID
  join c in adviceNoteEarnestMoneyTableEntities.ExitRec on b.PayReturnID equals c.ID
  join d in adviceNoteEarnestMoneyTableEntities.ContractSubReturnPayment.Where(y => y.PayType == 4) on c.ID equals d.RPID into t
  from d in t.DefaultIfEmpty()