LINQ to Entities中的案例陈述

时间:2013-07-25 19:51:10

标签: linq-to-entities

我有一个现有的LINQ to Entities查询,我需要添加一个case语句。在psuedo中,如果列CertType = 0,则从db.LWCertColls中提取注释,否则从db.LWCertLoans中提取注释(两个表中都存在注释列)。我知道下面的内容不起作用,但请注意if语句。我怎么能写这个呢?

           aryData =
                (From lwl In db.LWCertLoans _
                Join c In db.Loans _
           On c.LoanNum Equals lwl.LoanNum _
           Join p In db.LWCertColls _
           On lwl.CertID Equals p.CertID _
           Join r In db.RespCntrs _
           On r.BranchNum Equals c.BranchNum _
           Join cert In db.LWCerts
           On cert.LWCertID Equals lwl.CertID _
           Where p.LoanNum = lwl.LoanNum _
           Select New With { _
               .ToBeProcessedDate = cert.ToBeProcessedDate, _
            .CertType = cert.CertType, _
            .CertCollID = p.CertCollID, _
            .CertificateID = p.CertID, _
            .LoanNumberTypeAndCurrencyCombined = c.LoanNum, _
            .LoanType = c.LoanType, _
            .CurrType = r.CurrType, _
            .CollanteralBalance = c.ColCurBal, _
            .SalesAdditions = p.Sales, _
            .CreditMemos = p.Credits, _
            .CashRemovals = p.NetCollect, _
            .NonDilutiveAdjustment = p.PlusAdj, _
            .Discounts = p.Discounts, _
            .NonARCash = p.NonARCash, _
            .DilutiveAdjustment = p.NegAdj, _
            .LWCertCollsComments = p.Comments, _
            .StatusCode = p.StatusCode, _
            .CertLoanID = lwl.CertLoanID, _
            .Modified = lwl.Modified, _
            .LoanNum = lwl.LoanNum, _
            .EffectiveDate = lwl.EffectiveDate, _
            .RepWireNumber = lwl.RepWireNumber, _
            .Advance = lwl.Advance, _
            .ModifiedDate = lwl.ModifiedDate, _
            .DDAAccountName = lwl.DDAAccountName, _
            .LWCertLoansComments = lwl.Comments, _

    if cert.CertType = 0 then
             .Comment = p.Comments
    else
     .Comment = lwl.Comments
    end if


    }).ToArray()

1 个答案:

答案 0 :(得分:1)

.Comment = cert.CertType = 0 ? p.Comments : lwl.Comments

关于linq,这个语法不是100%肯定。