Chris
Chris

Reputation: 815

Case Statement in LINQ to Entities

I have an existing LINQ to Entities query that i need to add a case statement to. In psuedo, if the column CertType = 0, then pull comments from db.LWCertColls, else pull comments from db.LWCertLoans (Comments column exists in both tables). I know the below does not work, but notice the if statement. How could i write that to work?

           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()

Upvotes: 1

Views: 2725

Answers (1)

Brad M
Brad M

Reputation: 7898

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

Not 100% sure on this syntax with regards to linq though.

Upvotes: 1

Related Questions