title: Is detach necessary when updating record?
body: <p>I am working with <code>VS2013</code>, <code>.NET4.5</code>, <code>EF6</code> and <code>SQL 2008</code>. </p>
  
  <p>I have noticed that one of developers in our team changed all the update statements from </p>
  
  <pre><code>if (!journey.WillAnswer.Any()) 
  {
      db.WillAnswer.Add(willAnswer);
  } 
  else 
  {
      db.WillAnswer.Attach(willAnswer);
      db.Entry(willAnswer).State = EntityState.Modified;
  }
  
  db.SaveChanges();
  </code></pre>
  
  <p>to</p>
  
  <pre><code>if (!journey.WillAnswer.Any()) 
  {
      db.WillAnswer.Add(willAnswer);
  } 
  else 
  {
      var will = db.WillAnswer.Single(x =&gt; x.Id == willAnswer.Id);
  
      db.Detach(will);
      db.WillAnswer.Attach(willAnswer);
      db.Entry(willAnswer).State = EntityState.Modified;
  }
  
  db.SaveChanges();
  </code></pre>
  
  <p><strong>Is detach necessary? Is it good practice?</strong></p>