Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Foreach循环中获取的Dataset/JSON非常慢,不是';看起来不是数据库调用的问题_C#_Asp.net Mvc - Fatal编程技术网

C# 在Foreach循环中获取的Dataset/JSON非常慢,不是';看起来不是数据库调用的问题

C# 在Foreach循环中获取的Dataset/JSON非常慢,不是';看起来不是数据库调用的问题,c#,asp.net-mvc,C#,Asp.net Mvc,这是数据库调用- if (status == ValuationFilter.All) { valuations = db.Valuations.Where(v => ((v.Creationdate >= startDate && v.Creationdate <= endDate) || v.SI47Instruction.Count(s

这是数据库调用-

 if (status == ValuationFilter.All)
                {
                    valuations = db.Valuations.Where(v => ((v.Creationdate >= startDate && v.Creationdate <= endDate) ||
                        v.SI47Instruction.Count(s => s.RequestDateTime >= startDate && s.RequestDateTime <= endDate) > 0)).Include(t => t.SI47Instruction).ToArray();
                }
if(status==ValuationFilter.All)
{
估价=数据库估价。其中(v=>((v.Creationdate>=startDate和&v.Creationdate s.RequestDateTime>=startDate和&s.RequestDateTime 0))。包括(t=>t.si47指令)。ToArray();
}
下面是Foreach循环,在该循环中收集数据并发送到前端

            foreach (var item in valuations)
            {
                var valuationActiveAction = Action.GetActiveActionByValuationAndCompany(item.Id, companyId);
                var valuationReport = Report.GetByValuationId(item.Id);

                var dashboardItem = new Domain.DTO.DashboardItem
                {
                    //PropertyTitle = item.Property.Address1,
                    //PropertyFullAddress = String.Format("{0} {1} {2}", item.Property.Address1, item.Property.Address2, item.Property.City),
                    PropertyTitle = (String.Format("{0}{1} {2}{3} {4}", item.Property.Address1.Replace(",", ""), ",", String.IsNullOrEmpty(item.Property.Address2) ? "" : item.Property.Address2.Replace(",", ""), ",", item.Property.City)).Replace(", ,", ","),
                    PropertyFullAddress = (String.Format("{0}{1} {2}{3} {4}", item.Property.Address1.Replace(",", ""), ",", String.IsNullOrEmpty(item.Property.Address2) ? "" : item.Property.Address2.Replace(",", ""), ",", item.Property.City)).Replace(", ,", ","),
                    Originator = db.Companies.Where(c => c.Id == item.OriginationCompanyId).First().Name,
                    Valuer = item.ValuationCompanyId > 0 ? String.Format("{0} {1} {2}", db.Companies.Where(c => c.Id == item.ValuationCompanyId).First().Name, "-", db.Companies.Where(c => c.Id == item.ValuationCompanyId).First().Telephone) : "",
                    Notes = item.Note,
                    Action = valuationActiveAction.Type,
                    BorrowersName = item.BorrowerName
                };

                if (item.HasBeenDeclined.HasValue && item.HasBeenDeclined.Value && companyType == CompanyType.VMSI)
                {
                    var declinedReasons = ValuationDeclined.GetByValuationIdForDashboard(item.Id);
                    dashboardItem.DeclineReasons = declinedReasons.Length > 0 ? declinedReasons : null;
                }

                if (item.SI47Instruction.Count > 0)
                {
                    var lastestSI47 = item.SI47Instruction.OrderByDescending(s => s.Id).FirstOrDefault();

                    switch(status)
                    {
                        case ValuationFilter.Completed:
                            if (lastestSI47.Status != (int)InstructionStatus.SI47ReportComplete)
                            {
                                continue;
                            }
                            break;
                        case ValuationFilter.CompletedWithDrawn:
                            if (lastestSI47.Status != (int)InstructionStatus.SI47ReportComplete &&
                                lastestSI47.Status != (int)InstructionStatus.Withdrawn)
                            {
                                continue;
                            }
                            break;
                        case ValuationFilter.InProgress:
                            if (lastestSI47.Status == (int)InstructionStatus.SI47ReportComplete ||
                                lastestSI47.Status == (int)InstructionStatus.Withdrawn)
                            {
                                continue;
                            }
                            break;
                        case ValuationFilter.InProgressCompleted:
                            if (lastestSI47.Status == (int)InstructionStatus.Withdrawn)
                            {
                                continue;
                            }
                            break;
                        case ValuationFilter.InProgressWithdrawn:
                            if (lastestSI47.Status == (int)InstructionStatus.SI47ReportComplete)
                            {
                                continue;
                            }
                            break;
                        case ValuationFilter.Withdrawn:
                            if (lastestSI47.Status != (int)InstructionStatus.Withdrawn)
                            {
                                continue;
                            }
                            break;
                    }

                    List<SI47.Instruction> si47Instructions = new List<SI47.Instruction>();
                    foreach (var si47Instruction in item.SI47Instruction)
                    {
                        si47Instructions.Add(new SI47.Instruction(si47Instruction));
                    }

                    if (si47Instructions.Count > 0)
                    {
                        dashboardItem.Type = InstructionType.SI47;

                        var activeSI47 = si47Instructions.OrderByDescending(c => c.Creationdate).First();
                        var activeSI47InstructionReport = SI47.Report.GetByInstructionId(activeSI47.Id);


                        dashboardItem.RequestId = activeSI47.Id;
                        dashboardItem.StandardInstructionId = activeSI47.StandardRequestId;
                        dashboardItem.Status = (Domain.Enumerations.InstructionEnumerations.InstructionStatus)activeSI47.Status;
                        dashboardItem.Date = activeSI47.Creationdate;

                        if (SuperBank >= 1)
                        {
                            dashboardItem.ReportId = activeSI47InstructionReport.Id;
                        }
                        else
                        {
                            dashboardItem.ReportId = companyType == Domain.Enumerations.Security.CompanyType.Origination ? 0 : activeSI47InstructionReport.Id;
                        }
                        dashboardItem.CompletionDate = activeSI47.DateReportSigned;

                        if (companyType == CompanyType.Origination || companyType == CompanyType.VMSI)
                        {
                            dashboardItem.RevalDate = activeSI47.RevalDate;
                        }

                        List<Domain.DTO.DashboardPreviousInstruction> prevInstructionList = new List<Domain.DTO.DashboardPreviousInstruction>();
                        // add Standard Request to list of previous instructions
                        prevInstructionList.Add(new Domain.DTO.DashboardPreviousInstruction()
                            {
                                Id = item.Id,
                                Alerts = Business.Valuation.Alert.GetDescriptionsForMultipleToDashboard(valuationReport.Alerts.Select(i => (int)i).ToArray()),
                                InspectionDate = item.DateInspection,
                                InstructionDate = item.Creationdate,
                                ReportCompletedDate = item.DateReportSigned.Value,
                                ReportId = valuationReport.Id,
                                AppointmentDate = item.Deadline,
                                Type = "Standard"
                            });

                        // add remaining SI47 Instruction to previous instructions
                        if (si47Instructions.Count > 1)
                        {
                            var previousSI47List = si47Instructions.Where(t => !t.IsActive).ToArray();

                            foreach (var prevSI47 in previousSI47List)
                            {
                                var prevSI47InstructionReport = SI47.Report.GetByInstructionId(prevSI47.Id);

                                prevInstructionList.Add(new Domain.DTO.DashboardPreviousInstruction()
                                {
                                    Id = prevSI47.Id,
                                    Alerts = new string[0],
                                    InstructionDate = prevSI47.Creationdate,
                                    ReportCompletedDate = prevSI47.DateReportSigned.Value,
                                    ReportId = prevSI47InstructionReport.Id,
                                    Type = "SI47"
                                });
                            }
                        }

                        dashboardItem.PreviousInstructions = prevInstructionList.ToArray();
                    }
                }
                else
                {
                    dashboardItem.Type = InstructionType.Standard;
                    dashboardItem.StandardInstructionId = item.Id;
                    dashboardItem.RequestId = item.Id;
                    dashboardItem.Status = (Domain.Enumerations.InstructionEnumerations.InstructionStatus)item.Status;
                    dashboardItem.Date = item.Creationdate;
                    dashboardItem.Appointment = item.Deadline;
                    if (SuperBank >= 1)
                    {
                        dashboardItem.ReportId = valuationReport.Id;
                    }
                    else
                    {
                        dashboardItem.ReportId = companyType == Domain.Enumerations.Security.CompanyType.Origination ? 0 : valuationReport.Id;
                    }
                    dashboardItem.CompletionDate = item.DateReportSigned;
                    dashboardItem.InspectionDate = item.DateInspection;

                    if (item.HasAlerts.HasValue && item.HasAlerts.Value)
                    {
                        dashboardItem.Alerts = Business.Valuation.Alert.GetDescriptionsForMultipleToDashboard(valuationReport.Alerts.Select(i => (int)i).ToArray());
                    }

                    if (companyType == CompanyType.Origination || companyType == CompanyType.VMSI)
                    {
                        dashboardItem.RevalDate = item.RevalDate;
                    }

                    dashboardItem.PreviousInstructions = new Domain.DTO.DashboardPreviousInstruction[0];

                }

                result.Add(dashboardItem);
            }
        }

        return result.OrderBy(i => i.Date).ToArray();
    }


            foreach (var item in valuations)
            {
                var valuationActiveAction = Action.GetActiveActionByValuationAndCompany(item.Id, companyId);
                var valuationReport = Report.GetByValuationId(item.Id);

                var dashboardItem = new Domain.DTO.DashboardItem
                {
                    //PropertyTitle = item.Property.Address1,
                    //PropertyFullAddress = String.Format("{0} {1} {2}", item.Property.Address1, item.Property.Address2, item.Property.City),
                    PropertyTitle = (String.Format("{0}{1} {2}{3} {4}", item.Property.Address1.Replace(",", ""), ",", String.IsNullOrEmpty(item.Property.Address2) ? "" : item.Property.Address2.Replace(",", ""), ",", item.Property.City)).Replace(", ,", ","),
                    PropertyFullAddress = (String.Format("{0}{1} {2}{3} {4}", item.Property.Address1.Replace(",", ""), ",", String.IsNullOrEmpty(item.Property.Address2) ? "" : item.Property.Address2.Replace(",", ""), ",", item.Property.City)).Replace(", ,", ","),
                    Originator = db.Companies.Where(c => c.Id == item.OriginationCompanyId).First().Name,
                    Valuer = item.ValuationCompanyId > 0 ? String.Format("{0} {1} {2}", db.Companies.Where(c => c.Id == item.ValuationCompanyId).First().Name, "-", db.Companies.Where(c => c.Id == item.ValuationCompanyId).First().Telephone) : "",
                    Notes = item.Note,
                    Action = valuationActiveAction.Type,
                    BorrowersName = item.BorrowerName
                };

                if (item.HasBeenDeclined.HasValue && item.HasBeenDeclined.Value && companyType == CompanyType.VMSI)
                {
                    var declinedReasons = ValuationDeclined.GetByValuationIdForDashboard(item.Id);
                    dashboardItem.DeclineReasons = declinedReasons.Length > 0 ? declinedReasons : null;
                }

                if (item.SI47Instruction.Count > 0)
                {
                    var lastestSI47 = item.SI47Instruction.OrderByDescending(s => s.Id).FirstOrDefault();

                    switch(status)
                    {
                        case ValuationFilter.Completed:
                            if (lastestSI47.Status != (int)InstructionStatus.SI47ReportComplete)
                            {
                                continue;
                            }
                            break;
                        case ValuationFilter.CompletedWithDrawn:
                            if (lastestSI47.Status != (int)InstructionStatus.SI47ReportComplete &&
                                lastestSI47.Status != (int)InstructionStatus.Withdrawn)
                            {
                                continue;
                            }
                            break;
                        case ValuationFilter.InProgress:
                            if (lastestSI47.Status == (int)InstructionStatus.SI47ReportComplete ||
                                lastestSI47.Status == (int)InstructionStatus.Withdrawn)
                            {
                                continue;
                            }
                            break;
                        case ValuationFilter.InProgressCompleted:
                            if (lastestSI47.Status == (int)InstructionStatus.Withdrawn)
                            {
                                continue;
                            }
                            break;
                        case ValuationFilter.InProgressWithdrawn:
                            if (lastestSI47.Status == (int)InstructionStatus.SI47ReportComplete)
                            {
                                continue;
                            }
                            break;
                        case ValuationFilter.Withdrawn:
                            if (lastestSI47.Status != (int)InstructionStatus.Withdrawn)
                            {
                                continue;
                            }
                            break;
                    }

                    List<SI47.Instruction> si47Instructions = new List<SI47.Instruction>();
                    foreach (var si47Instruction in item.SI47Instruction)
                    {
                        si47Instructions.Add(new SI47.Instruction(si47Instruction));
                    }

                    if (si47Instructions.Count > 0)
                    {
                        dashboardItem.Type = InstructionType.SI47;

                        var activeSI47 = si47Instructions.OrderByDescending(c => c.Creationdate).First();
                        var activeSI47InstructionReport = SI47.Report.GetByInstructionId(activeSI47.Id);


                        dashboardItem.RequestId = activeSI47.Id;
                        dashboardItem.StandardInstructionId = activeSI47.StandardRequestId;
                        dashboardItem.Status = (Domain.Enumerations.InstructionEnumerations.InstructionStatus)activeSI47.Status;
                        dashboardItem.Date = activeSI47.Creationdate;

                        if (SuperBank >= 1)
                        {
                            dashboardItem.ReportId = activeSI47InstructionReport.Id;
                        }
                        else
                        {
                            dashboardItem.ReportId = companyType == Domain.Enumerations.Security.CompanyType.Origination ? 0 : activeSI47InstructionReport.Id;
                        }
                        dashboardItem.CompletionDate = activeSI47.DateReportSigned;

                        if (companyType == CompanyType.Origination || companyType == CompanyType.VMSI)
                        {
                            dashboardItem.RevalDate = activeSI47.RevalDate;
                        }

                        List<Domain.DTO.DashboardPreviousInstruction> prevInstructionList = new List<Domain.DTO.DashboardPreviousInstruction>();
                        // add Standard Request to list of previous instructions
                        prevInstructionList.Add(new Domain.DTO.DashboardPreviousInstruction()
                            {
                                Id = item.Id,
                                Alerts = Business.Valuation.Alert.GetDescriptionsForMultipleToDashboard(valuationReport.Alerts.Select(i => (int)i).ToArray()),
                                InspectionDate = item.DateInspection,
                                InstructionDate = item.Creationdate,
                                ReportCompletedDate = item.DateReportSigned.Value,
                                ReportId = valuationReport.Id,
                                AppointmentDate = item.Deadline,
                                Type = "Standard"
                            });

                        // add remaining SI47 Instruction to previous instructions
                        if (si47Instructions.Count > 1)
                        {
                            var previousSI47List = si47Instructions.Where(t => !t.IsActive).ToArray();

                            foreach (var prevSI47 in previousSI47List)
                            {
                                var prevSI47InstructionReport = SI47.Report.GetByInstructionId(prevSI47.Id);

                                prevInstructionList.Add(new Domain.DTO.DashboardPreviousInstruction()
                                {
                                    Id = prevSI47.Id,
                                    Alerts = new string[0],
                                    InstructionDate = prevSI47.Creationdate,
                                    ReportCompletedDate = prevSI47.DateReportSigned.Value,
                                    ReportId = prevSI47InstructionReport.Id,
                                    Type = "SI47"
                                });
                            }
                        }

                        dashboardItem.PreviousInstructions = prevInstructionList.ToArray();
                    }
                }
                else
                {
                    dashboardItem.Type = InstructionType.Standard;
                    dashboardItem.StandardInstructionId = item.Id;
                    dashboardItem.RequestId = item.Id;
                    dashboardItem.Status = (Domain.Enumerations.InstructionEnumerations.InstructionStatus)item.Status;
                    dashboardItem.Date = item.Creationdate;
                    dashboardItem.Appointment = item.Deadline;
                    if (SuperBank >= 1)
                    {
                        dashboardItem.ReportId = valuationReport.Id;
                    }
                    else
                    {
                        dashboardItem.ReportId = companyType == Domain.Enumerations.Security.CompanyType.Origination ? 0 : valuationReport.Id;
                    }
                    dashboardItem.CompletionDate = item.DateReportSigned;
                    dashboardItem.InspectionDate = item.DateInspection;

                    if (item.HasAlerts.HasValue && item.HasAlerts.Value)
                    {
                        dashboardItem.Alerts = Business.Valuation.Alert.GetDescriptionsForMultipleToDashboard(valuationReport.Alerts.Select(i => (int)i).ToArray());
                    }

                    if (companyType == CompanyType.Origination || companyType == CompanyType.VMSI)
                    {
                        dashboardItem.RevalDate = item.RevalDate;
                    }

                    dashboardItem.PreviousInstructions = new Domain.DTO.DashboardPreviousInstruction[0];

                }

                result.Add(dashboardItem);
            }
        }

        return result.OrderBy(i => i.Date).ToArray();
    }
foreach(估值中的var项目)
{
var valuationActiveAction=Action.GetActiveActionByValuationAndCompany(item.Id,companyId);
var valuationReport=Report.GetByValuationId(item.Id);
var dashboardItem=新域.DTO.dashboardItem
{
//PropertyTitle=item.Property.Address1,
//PropertyFullAddress=String.Format(“{0}{1}{2}”、item.Property.Address1、item.Property.Address2、item.Property.City),
PropertyTitle=(String.Format(“{0}{1}{2}{3}{4}”,item.Property.Address1.Replace(“,”,”),“,”,String.IsNullOrEmpty(item.Property.Address2)?”:item.Property.Address2.Replace(“,”,“,”,“,”,“,”,item.Property.City)).Replace(“,”,”).Replace(,“,”,“,”,”,
PropertyFullAddress=(String.Format(“{0}{1}{2}{3}{4}”,item.Property.Address1.Replace(“,”,”),“,”,String.IsNullOrEmpty(item.Property.Address2)?”:item.Property.Address2.Replace(“,”,“,”,”,“,”,”,“,”,item.Property.City)).Replace(“,”,”,“,”,
发起人=db.companys.Where(c=>c.Id==item.OriginationCompanyId).First().Name,
Valuer=item.ValuationCompanyId>0?String.Format(“{0}{1}{2}”,db.Companies.Where(c=>c.Id==item.ValuationCompanyId).First().Name,“-”,db.Companies.Where(c=>c.Id==item.ValuationCompanyId).First().phone):“”,
注释=项目。注释,
Action=valuationactivation.Type,
借入者名称=item.借入者名称
};
if(item.hasbeendecline.HasValue&&item.hasbeendecline.Value&&companyType==companyType.VMSI)
{
var declinedReasons=估值下降。GetByValuationIdForDashboard(item.Id);
dashboardItem.declinedReasons=declinedReasons.Length>0?declinedReasons:null;
}
如果(item.SI47Instruction.Count>0)
{
var lastestSI47=item.si47指令.OrderByDescending(s=>s.Id).FirstOrDefault();
开关(状态)
{
案例评估筛选器。已完成:
if(lastestSI47.Status!=(int)指令Status.SI47ReportComplete)
{
继续;
}
打破
案例评估筛选器.CompletedRetracted:
如果(lastestSI47.Status!=(int)指令Status.SI47ReportComplete&&
lastestSI47.状态!=(int)指令状态已撤销)
{
继续;
}
打破
案例评估筛选器.InProgress:
如果(lastestSI47.Status==(int)指令Status.SI47ReportComplete||
LastTestSi47.Status==(int)指令Status.Retracted)
{
继续;
}
打破
案例评估筛选器.InProgressCompleted:
if(lastestSI47.Status==(int)指令Status.dralled)
{
继续;
}
打破
案例评估筛选器.InProgressRetracted:
if(lastestSI47.Status==(int)指令Status.SI47ReportComplete)
{
继续;
}
打破
案例评估过滤器。已撤销:
if(lastestSI47.Status!=(int)指令状态已撤销)
{
继续;
}
打破
}
List SI47指令=新列表();
foreach(项目SI47指令中的var SI47指令)
{
SI47指令。添加(新的SI47指令(SI47指令));
}
如果(si47Instructions.Count>0)
{
dashboardItem.Type=InstructionType.SI47;
var activeSI47=si47Instructions.OrderByDescending(c=>c.Creationdate.First();
var activeSI47InstructionReport=SI47.Report.GetByInstructionId(activeSI47.Id);
dashboardItem.RequestId=activeSI47.Id;
dashboardItem.StandardInstructionId=activeSI47.StandardRequestId;
dashboardItem.Status=(Domain.Enumerations.InstructionOneNumerations.InstructionStatus)activeSI47.Status;
dashboardItem.Date=activeSI47.Creationdate;
如果(超级银行>=1)
{
dashboardItem.ReportId=activeSI47InstructionReport.Id;
}
其他的
{
dashboardItem.ReportId=companyType==Domain.Enumerations.Security.companyType.Origination?0:activeSI47Inst
Originator = db.Companies.Where(c => c.Id == tem.OriginationCompanyId).First().Name
valuations = db.Valuations.Where(v => ((v.Creationdate >= startDate && v.Creationdate <= endDate) || 
    v.SI47Instruction.Count(s => s.RequestDateTime >= startDate 
    && s.RequestDateTime <= endDate) > 0))
    .Include(t => t.SI47Instruction)
    .Include(c => c.OriginationCompany)
    .ToArray();
Originator = item.OriginatorCompany.Name,