title: C# Update or insert from a List by some criteria
body: <p>I have 2 lists, both with a different number of items, both with 1 parameter in common that I have to compare. If the value of the parameter is the same I have to <em>update</em> the DB, but if the item in a list doesn't have an item in the second list, I have to <em>insert it</em> into the DB.</p>
  
  <p>This is what I was trying:</p>
  
  <pre class="lang-cs prettyprint-override"><code>foreach (var rep in prodrep)
  {
      foreach (var crm in prodcrm)
      {
          if (rep.VEHI_SERIE.Equals(crm.VEHI_SERIE))
          {
              updateRecord(rep.Data);
  
          } 
          else 
          {
              insertRecords(rep.Data);
          }
      }  
  } 
  </code></pre>
  
  <p>The first problem with this is that it is very slow. The second problem is that obviously the insert statement would't work, but I don't want to do another for each inside a <code>foreach</code> to verify if it doesn't exist, because that would take double the time.</p>
  
  <p>How can I make this more efficient? </p>