title: Entity Framework: EF always saves values "on top" of old values
body: <p>In my ASP.NET MVC Application where I use Entity Framework, I discovered a strange behavior while saving. I have a view, where I check if customers in the data base exist, if thats true, they will be displayed with their data in a table. Works fine. The user can add more customers to the table, to illustrate that, a small Example:</p>
  
  <p>Database contains the customers John and Jim. They are displayed in the table. The user adds 2 customers to the table: Peter and Jack, so now the table should contain the customers: John, Jim, Peter and Jack.</p>
  
  <p>So what happens now is, when I save them in my controller. The customers that are saved, are John, Jim, John, Jim, Peter and Jack. Entity Framework seems to add those on top, of the customers before, but thats not what I want, I just want to save those customers, like they are displayed in the table. I hope you can help me out on this.</p>
  
  <p>Here is the code in my controller to save the customers:</p>
  
  <pre><code>var counter = 0;
  string customerName = "";
  
  while (true)
  {
  customerName = Request.Form["CustomerName[" + counter + "]"];
  if (customerName == "" || customerName == null)
  {
     break;
  }
  Customer customer = new Customer();
  customer.OverviewID = CustomerOverview.ID;
  customer.Name = customerName;
  db.Customer.Add(customer);
  db.SaveChanges();
  counter++;
  }
  </code></pre>
  
  <p>Here is how I add the existing customers to the table in the view:</p>
  
  <pre><code>@{
      if (Model.Customers.Count() &gt; 0)
      {
  
          foreach (var customer in Model.Cusomters)
          {
              &lt;text&gt;ArrayCustomers.push("@(customer.Name)");&lt;/text&gt;
          }
      }
      else
      {
              &lt;text&gt;ArrayCustomers.push("");&lt;/text&gt;
      }
  }
      refresh_table();
  </code></pre>