【问题标题】:Linq orderby same field different valueLinq orderby相同的字段不同的值
【发布时间】:2017-05-31 07:43:20
【问题描述】:

我有这个问题:

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 的贷款开头。

知道如何实现吗?

【问题讨论】:

  • 您希望 4-8 位于底部无序还是根本不想要?
  • @FilipCordas 在底部谢谢

标签: c# entity-framework linq linq-to-sql linq-to-entities


【解决方案1】:

我认为这会满足您的要求。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-06
    • 1970-01-01
    • 2016-02-12
    • 1970-01-01
    • 2020-06-29
    • 2017-05-17
    • 2017-08-26
    • 1970-01-01
    相关资源
    最近更新 更多