Note that there are some explanatory texts on larger screens.

plurals
  1. POvery slow conversion of query to list
    text
    copied!<p>I'm querying from a single view to retrieve a list of indicators. All the properties of an indicator can be retrieved from that single view.</p> <p>Here's the code:</p> <pre><code>data = new DataContext(); var core = from item in data.Items where countryIDs.Contains(item.CountryId) &amp;&amp; indicatorIDs.Contains(item.IndicatorId) orderby item.Indicator select item; var x = from item in core.Distinct() group item by new { item.IndicatorId, item.Indicator } into indicator select new { IndicatorID = indicator.Key.IndicatorId, IndicatorDescription = indicator.Key.Indicator, Genders = from g in core where g.Gender != null &amp;&amp; g.IndicatorId == indicator.Key.IndicatorId select new Gender { GenderID = g.GenderId, GenderDescription = g.Gender }, HasGender = (from g in core where g.Gender != null &amp;&amp; g.IndicatorId == indicator.Key.IndicatorId select g.GenderId).Count() &gt; 0, AreaTypes = from rat in core where rat.IndicatorId == indicator.Key.IndicatorId &amp;&amp; rat.AreaType != null select new AreaType { AreaTypeId = rat.AreaTypeId, AreaDescription = rat.AreaType }, HasAreaType = (from rat in core where rat.IndicatorId == indicator.Key.IndicatorId &amp;&amp; rat.AreaType != null select rat.AreaTypeId).Count() &gt; 0, Sectors = from s in core where s.IndicatorId == indicator.Key.IndicatorId &amp;&amp; s.Sector != null select new Sector { SectorID = s.SectorId, Title = s.Sector }, HasSector = (from s in core where s.IndicatorId == indicator.Key.IndicatorId &amp;&amp; s.Sector != null select s.SectorId).Count() &gt; 0 }; List&lt;Indicator&gt; indicators = new List&lt;Indicator&gt;(); Indicator i = new Indicator(); foreach (var item in x) { i = new Indicator() { IndicatorID = item.IndicatorID, IndicatorDescription = item.IndicatorDescription, Genders = item.Genders.ToList(), AreaTypes = item.AreaTypes.ToList(), Sectors = item.Sectors.ToList(), HasGender = item.HasGender, HasAreaType = item.HasAreaType, HasSector = item.HasSector }; indicators.Add(i); } return indicators; </code></pre> <p>It slows down when it reaches the foreach loop, when x is transformed. Is there any way to make this query convert to a list faster? Thank you.</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