linq左外联多表多条件将多条数据合并成一条

           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();

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值