在Linq中选择IsNull

时间:2014-08-12 14:42:17

标签: sql linq

我如何在linq中写这个:

SELECT
    c.customerNumber,
    IsNull(l.loanNumber, '') AS loanNumber,
    dd.documentTypeName,
    dd.documentSubTypeName,
    d.filename,
    (SELECT propertyId FROM SystemProperties WHERE propertyKey LIKE 'acculoan.inputType.Other') AS inputType
FROM
    document AS d INNER JOIN qryDocumentDefinitions AS dd
        ON d.documentDefId = dd.documentDefId
        AND d.documentId =  @DocumentId
    INNER JOIN customer AS c
        ON c.customerId = d.customerId
    LEFT OUTER JOIN loan AS l
        ON l.loanId=d.loanId

特别是isnull和嵌套选择需要帮助。

非常感谢提前..!

1 个答案:

答案 0 :(得分:0)

您可以尝试以下(无法测试,可能需要进行一些调整,但应采用相同的形式);

from Doc in db.document 
join DocDef in db.qryDocumentDefinitions on doc.documentDefId equals DocDef.documentDefId 
join Cus in db.Customer on Cus.customerId = Doc.customerId
from loan in db.loan 
     .Where(loan => loan.loanId == Doc.loanId).DefaultIfEmpty()
select new
    {
         CustNo= Cus.customerNumber
        ,loan == null ? "" : loan.loanNumber
        ,DocType= DocDef.documentTypeName
        ,DocSubType= DocDef.documentSubTypeName
        ,filename = Doc.filename
        ,inputType = (?int)(from Sys in db.SystemProperties 
                              where Sys.propertyKey.Contains("acculoan.inputType.Other")
    }