title: Optimize code: Linq and foreach loop 15k records
body: <p>this is my code</p>
  
  <pre><code>void fixInstellingenTabel(object source, ElapsedEventArgs e)
  {
      NASDataContext _db = new NASDataContext();
  
      List&lt;Instellingen&gt; newOnes = new List&lt;Instellingen&gt;();
  
      List&lt;InstellingGegeven&gt; li = _db.InstellingGegevens.ToList();
      foreach (InstellingGegeven i in li) {
          if (_db.Instellingens.Count(q =&gt; q.INST_LOC_REF == i.INST_LOC_REF &amp;&amp; q.INST_LOCNR == i.INST_LOCNR &amp;&amp; q.INST_REF == i.INST_REF &amp;&amp; q.INST_TYPE == i.INST_TYPE) &lt;= 0) {
              // There is no item yet. Create one.
              Instellingen newInst = new Instellingen();
              newInst.INST_LOC_REF = i.INST_LOC_REF;
              newInst.INST_LOCNR = i.INST_LOCNR;
              newInst.INST_REF = i.INST_REF;
              newInst.INST_TYPE = i.INST_TYPE;
              newInst.Opt_KalStandaard = false;
              newOnes.Add(newInst);
          }
      }
      _db.Instellingens.InsertAllOnSubmit(newOnes);
      _db.SubmitChanges();
  }
  </code></pre>
  
  <p>basically, the InstellingGegevens table gest filled in by some procedure from another server.
  the thing i then need to do is check if there are new records in this table, and fill in the new ones in Instellingens.</p>
  
  <p>this code runs for like 4 minutes on 15k records. how do I optimize it? or is the only way a Stored Procedure?</p>
  
  <p>this code runs in a timer, running every 6h. IF a stored procedure is best, how to I use that in a timer?</p>
  
  <pre><code>        Timer Tim = new Timer(21600000); //6u
          Tim.Elapsed += new ElapsedEventHandler(fixInstellingenTabel);
          Tim.Start();
  </code></pre>