LINQ到实体的案例声明 [英] Case Statement in LINQ to Entities

查看:68
本文介绍了LINQ到实体的案例声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

不过,对于linq来说,并不是100%都可以肯定这种语法.

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

这篇关于LINQ到实体的案例声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆