主表连子表连两次取两个值 一条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 query2一个查询,其中用let关键字使用你的query作为自查询。
反正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