左连接在linq中有多个列和常量值

时间:2014-09-29 16:17:40

标签: c# sql linq join

我试图在LINQ中为两个表创建一个左连接,但其中一个表需要一个常量的连接值。

纯SQL中的查询是

select 
    cf.idCreditForm ,q3.FacturadaenSAP 
from 
    Panacredit.dbo.pet_CreditForm cf
left join 
    Panacredit.dbo.cat_customentity_crediqcr3 q3 on cf.idCreditForm = q3.IdEntityItem 
                                                 and q3.IdType = 7
where  
    cf.opStatus = 6  
    and cf.idSubStatus = 72

到目前为止,我的LINQ代码是

solicitudes =
    from sol in ElContexto.pet_CreditForms
    join cq3 in ElContexto.cat_customentity_crediqcr3s
    on new { sol.idCreditForm, 7 } = new { cq3.IdEntityItem , cq3.IdType }
    into solicCq3
    where sol.approvedDate >= iniDateJul
       && sol.approvedDate <= endDateJul
       && sol.opStatus == 6
       && sol.idCompany == idcompany
       && sol.idSubStatus == subEst
       && sol.idBranch == idbranch
    from scq3 in solicCq3.DefaultIfEmpty()
    select new { sol.idCreditForm , cq3.FacturadaenSAP };

请帮帮我

1 个答案:

答案 0 :(得分:0)

q3.IdType = 7部分与联接无关。将其移至where子句。