Linq查询左连接 [英] Linq query for left join

查看:265
本文介绍了Linq查询左连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请找到以下linq查询。在这里它作为内部加入,但我需要它作为左加入

请帮助我修复这个



来自于IntegrationAudits加入的od in in在RT.IntegrationStatusID上的IntegrationStatus等于od.IntegrationStatusId

在IntegrationMasters中加入ct,od.IntegrationMasterId等于ct.IntegrationMasterId

其中ct.PackageName ==导出TF58361和TF58362和TF58363 &&

(pd.CreatedDate> = DateTime.Now && pd.CreatedDate< = DateTime.Now)

选择新{

ct.IntegrationEntity,ct.PackageName,pd.ImportStart,pd.ImportEnd,pd.ImportStatus

}









请帮助我,我是新来的。

Please find the below linq query. Here it works as Inner Join but I need it as Left Join
Please help me in fixing this

from pd in IntegrationAudits join od in IntegrationStatus on pd.IntegrationStatusID equals od.IntegrationStatusId
join ct in IntegrationMasters on od.IntegrationMasterId equals ct.IntegrationMasterId
where ct.PackageName == "Export TF58361 and TF58362 and TF58363" &&
(pd.CreatedDate >= DateTime.Now && pd.CreatedDate <= DateTime.Now)
select new {
ct.IntegrationEntity,ct.PackageName,pd.ImportStart,pd.ImportEnd,pd.ImportStatus
}




Please help me I am new to this.

推荐答案

看看这个:



加入Linq [ ^ ]


请找到修改后的版本,其中的更改以粗体显示。抱歉,我无法测试,如果有任何问题,请告诉我。



Please find the modified version with the changes appearing in bold. Sorry I could not test it, please let me know if there is any issue with this.

from pd in IntegrationAudits 

join od in IntegrationStatus on pd.IntegrationStatusID equals od.IntegrationStatusId into a1
join ct in IntegrationMasters on od.IntegrationMasterId equals ct.IntegrationMasterId into b1

where ct.PackageName == "Export TF58361 and TF58362 and TF58363" &&
(pd.CreatedDate >= DateTime.Now && pd.CreatedDate <= DateTime.Now)

from od in a1.DefaultIfEmpty()
from ct in b1.DefaultIfEmpty()
select new {
ct.IntegrationEntity,ct.PackageName,pd.ImportStart,pd.ImportEnd,pd.ImportStatus
}


这篇关于Linq查询左连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆