Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>TL;DR Remove the <code>AsEnumerable</code> call and replace it with an <code>AsQueryable</code> call and it should resolve most of the performance issues (outside of actual database execution cost being slow, which is fixed by adding indexes on columns you are filtering / joining on).</h2> <p><em>Explanation of what is actually happening...</em></p> <p>As soon as you call <code>AsEnumerable</code> you are now outside of Entity Framework and in the world of LINQ-to-objects. That means it's going to execute the query against the database when it is enumerated against. It doesn't matter that you call <code>AsQueryable</code> again, that merely means that you are creating a query against an in memory structure.</p> <p>The effective execution is this.</p> <ol> <li>Create an object query, including all FormFieldProperties linked to the form</li> <li>Transform the current IQueryable instance into an enumerable.</li> <li>Add a predicate against the enumerable instance which will only return items whose FormID value is one.</li> <li>Call ToList, which copies all values from source enumerable to a list.</li> </ol> <p>Now, up until step 4, the query actually hasn't queried the database. When you call <code>ToList</code>, it executes the query in step one (as you see). This query likely is expensive and takes a while because of the amount of data it is returning and/or missing indexes that may improve it's performance.</p> <p>Once that query is done and materialized, it's result is wrapped in an enumerator.</p> <p>Now, every object is iterated and checked to see if it matches the predicate that was added in step 3. If it does match, then it is returned to whoever is iterating over it (in this case, the ToList function).</p> <p>Now that the value has been returned, it is added to the list that is being created with the values. </p> <p>Finally, you get a list back from the <code>ToList</code> method, and it has exactly what you asked for, but it did all of that in memory rather than in the database.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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