2017-05-31 47 views
0

我有這個疑問:LINQ排序依據同一領域不同的值

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開頭的貸款。

任何想法如何實現這一目標?

謝謝,Laziale

+0

你想4-8在底部無序或你根本不想要嗎? –

+0

@FilipCordas在底部thx – Laziale

回答

0

我認爲這會做你想做的。

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 
       };