簡體   English   中英

Linq訂單由同一字段不同的值

[英]Linq orderby same field different value

我有這個查詢:

investorData = from investor in db.Investors
               join loanapp in db.LoanApplications on investor.FundID equals loanapp.FundID into loanAppData
               from lapp in loanAppData.DefaultIfEmpty()
               join fundreport in db.FundReportLoanDatas on lapp.LoanId equals fundreport.LoanId into fundReportData
               from freport in fundReportData.DefaultIfEmpty()
               where investor.FundID == fundID
               orderby lapp.LoanId descending
               select new InvestorPortfolioVM()
               {
                   InvestorId = investor.InvestorID,
                   CurrentLTV = freport.CurrentLTV == null ? 0.0 : freport.CurrentLTV,
                   LoanId = lapp.LoanId,
                   SegLTV = freport.SegLTV == string.Empty ? "" : freport.SegLTV,
                   BorrowerName = lapp.BorrowerName,
                   LoanStatusId = lapp.LoanStatusId
               };

我現在想要實現的是按一個字段(LoanStatusId)訂購商品,從沒有LoanStatusId為4或8的貸款開始。

知道我該如何實現嗎?

我認為這會做您想要的。

investorData = from investor in db.Investors
               join loanapp in db.LoanApplications on investor.FundID equals loanapp.FundID into loanAppData
               from lapp in loanAppData.DefaultIfEmpty()
               join fundreport in db.FundReportLoanDatas on lapp.LoanId equals fundreport.LoanId into fundReportData
               from freport in fundReportData.DefaultIfEmpty()
               where investor.FundID == fundID
               orderby (lapp.LoanId >= 4 &&  lapp.LoanId <= 8) ? 1 : 0
               select new InvestorPortfolioVM()
               {
                   InvestorId = investor.InvestorID,
                   CurrentLTV = freport.CurrentLTV == null ? 0.0 : freport.CurrentLTV,
                   LoanId = lapp.LoanId,
                   SegLTV = freport.SegLTV == string.Empty ? "" : freport.SegLTV,
                   BorrowerName = lapp.BorrowerName,
                   LoanStatusId = lapp.LoanStatusId
               };

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM