var lstResult = from A in oDataContext.T_BoardCPKCfg
join B in oDataContext.T_Board on A.BoardCode equals B.Code
join VB in oDataContext.T_VersionBoardCfg on B.ID equals VB.BoardID
join V in oDataContext.T_Version on VB.VersionID equals V.ID
join C in oDataContext.T_CPKItem on A.CPKItemName equals C.CPKItemName
join b1 in oDataContext.T_PreAlertCfg.Where(p => p.Type == type && p.PreAlertLevelID == 1 && p.Name == PrefAlertname)
on new { ID = C.ID, strBoardCode = A.BoardCode } equals new { ID = b1.TestItemID, strBoardCode = b1.BoardCode } into B1
from b1 in B1.DefaultIfEmpty()
join b2 in oDataContext.T_PreAlertCfg.Where(p => p.Type == type && p.PreAlertLevelID == 2 && p.Name == PrefAlertname)
on new { ID = C.ID, strBoardCode = A.BoardCode } equals new { ID = b2.TestItemID, strBoardCode = b2.BoardCode } into B2
from b2 in B2.DefaultIfEmpty()
join b3 in oDataContext.T_PreAlertCfg.Where(p => p.Type == type && p.PreAlertLevelID == 3 && p.Name == PrefAlertname)
on new { ID = C.ID, strBoardCode = A.BoardCode } equals new { ID = b3.TestItemID, strBoardCode = b3.BoardCode } into B3
from b3 in B3.DefaultIfEmpty()
where lstVersionID.Contains(V.ID)
select new BoardCPKItemCfg
{
ID = A.ID,
TestItemName = A.CPKItemName,
CPKItemName = C.ID,
Type = b1 == null ? 0 : b1.Type,
BoardCode = A.BoardCode,
BoardName = A.BoardName,
RedPreAlertID = b1 == null ? 0 : b1.PreAlertLevelID,
RedPreAlertValue = b1 == null ? 0 : (decimal)b1.PreAlertValue,
RedMailSendTo = b1.MailSendTo,
RedNoteSendTo = b1.NoteSendTo,
BluePreAlertID = b2 == null ? 0 : b2.PreAlertLevelID,
BluePreAlertValue = b2 == null ? 0 : (decimal)b2.PreAlertValue,
BlueMailSendTo = b2.MailSendTo,
BlueNoteSendTo = b2.NoteSendTo,
YellowPreAlertID = b3 == null ? 0 : b3.PreAlertLevelID,
YellowPreAlertValue = b3 == null ? 0 : (decimal)b3.PreAlertValue,
YellowMailSendTo = b3.MailSendTo,
YellowNoteSendTo = b3.NoteSendTo
};
lstPreAlertInfo = lstResult.ToList();
linq左外联多表多条件将多条数据合并成一条
最新推荐文章于 2022-08-25 09:18:23 发布