title: precompile a query execution in LINQ
body: <p>I am trying to improve the performance of the following codes in LINQ:</p>
  
  <pre><code>using (var db = new MyContext)
  { 
     foreach (var item in items)
     {
        Modal.StaffNo A = staff.StaffNo.Where(a =&gt; a.StaffType == staffType);
        staff.StaffNo.Add(A);
        ......
     }
  }
  </code></pre>
  
  <p>I found it takes 1 sec to go through each item in the loop and then I figured out it's the first query expression "staff.StaffNo.Where(a => a.StaffType == staffType)" which takes most of the time. So I precompiled the query using "CompiledQuery.Compile" and it did save a lot of time. </p>
  
  <p>However, the second query execution statement's execution time increased: "staff.StaffNo.Add(A);". Is there any way to precompiled that execution statement also?</p>
  
  <p>Many Thanks !!! </p>