方法链接性能问题

Method Chaining Performance Issues

我在找 recommendations/suggestions。我有一个很长的 运行 过程,我正在尝试优化它。这是最长的 运行 过程,每次调用 return 填充列表需要 1 分 48 秒。我用每个请求 1000 条记录循环处理这个,所以你可以想象分钟加起来有多快。我已将所有其他方法优化为每 1000 次不到 10 秒。我希望能够加快速度。

我试过预加载和延迟加载。预加载是迄今为止性能最好的。

如有任何建议,我们将不胜感激。

private List<SBLead> GetLoanList(IEnumerable<LoanCategoryMonitor> loans)
{
    return (loans.Where(selectedItem => selectedItem.Loan != null)
        .Select(selectedItem => new SBLead
        {
            ApiKey = _settings.apiKey,
            CrmId = selectedItem.LoanNumber.ToString(),
            CrmName = _crmName,
            LoanType = selectedItem.Loan.Loan_Type,
            Email = selectedItem.Loan.abcBorrower?.EMail_Address,
            FirstName = selectedItem.Loan?.Borr_First_Name,
            LastName = selectedItem.Loan?.Borr_Last_Name,
            Address = selectedItem.Loan?.Address,
            City = selectedItem.Loan?.City,
            State = selectedItem.Loan?.State,
            Zip = selectedItem.Loan?.Zip,
            Phone = string.Empty,
            WatchTypes = GetRequestedWatches(selectedItem.Category.GetEnumFromString<Category>()),
            UserEmail = _defaultLoanOfficerEmail,
            UserName = _defaultLoanOfficerName
        })).ToList();
}

public IEnumerable<LoanCategoryMonitor> GetLoans()
{
    var loanCollection = _be.LoanCategoryMonitors
        .Include(c => c.Loan)
        .Where(r => r.ReadyForUpdate == true && r.LoanExtracts == null &&
                    r.Category != Category.None.ToString())
        .AsNoTracking()
        .ToList();

    return loanCollection;
}

我找到了。我缺少 abcBorrower 的包含。新的执行速度几乎是瞬时的,我可以接受。每 1000 条记录可节省 1 分 48 秒。感谢输入

Email = selectedItem.Loan.abcBorrower?.EMail_Address,