Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen I call Tolist it takes so long to convert, how can I improve this?
    text
    copied!<p>I have the following bit of code and the last statement with the toList takes a long time. Any ideas how I can improve this?</p> <pre><code>//This statement takes less than 1 second var inspectorData = context.COESDetails.Where(x =&gt; x.UploadCOESDetails.AuditZoneId == criteria.AuditZoneId &amp;&amp; x.UploadCOESDetails.AuditMonth.Contains(criteria.AuditYear)).Select(x =&gt; x.Inspector).Where(y =&gt; y.Id != 0).Distinct().OrderBy(x =&gt; x.Firstname).ToList(); //This statement takes less than 1 second var coesData = context.COESDetails.Where(x =&gt; x.UploadCOESDetails.AuditZoneId == criteria.AuditZoneId &amp;&amp; x.UploadCOESDetails.AuditMonth.Contains(criteria.AuditYear)).ToList(); //this takes less than 1 second var nonComplianceData = inspectorData .Select(ud =&gt; new NonComplianceData { InspectorId = ud.Id, InspectorName = ud.Firstname + " " + ud.Surname, FullYearData = Constants.Months.Select(month =&gt; new MonthData { Month = month, TotalAuditsCompleted = coesData.Count(x =&gt; x.UploadCOESDetails.AuditZoneId == criteria.AuditZoneId &amp;&amp; x.UploadCOESDetails.AuditMonth == (month + " " + criteria.AuditYear) &amp;&amp; x.InspectorId == ud.Id &amp;&amp; x.AuditType != (int)AuditType.NotSelected), TotalNoDefects = coesData.Count(x =&gt; x.UploadCOESDetails.AuditZoneId == criteria.AuditZoneId &amp;&amp; x.UploadCOESDetails.AuditMonth == (month + " " + criteria.AuditYear) &amp;&amp; x.InspectorId == ud.Id &amp;&amp; x.AuditType != (int)AuditType.NotSelected &amp;&amp; x.COESDetailsCOESDefects.Any()) }).ToList() }); // this statement takes about 14 seconds return nonComplianceData.ToList(); </code></pre> <p>I thought when I called the toList() in the first two statements, I thought the query was being executed and I had the required data. So why is the last Tolist() taking so long? considering all the required data is there already..</p> <p>any insights? thoughts?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload