【问题标题】:Select IsNull in Linq在 Linq 中选择 IsNull
【发布时间】:2014-08-12 14:42:17
【问题描述】:

我如何在 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 和嵌套选择需要帮助。

提前非常感谢..!

【问题讨论】:

标签: sql linq


【解决方案1】:

你可以试试下面的(还没能测试,可能需要一些调整,但应该是一样的形式);

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")
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-29
    • 1970-01-01
    相关资源
    最近更新 更多