title: Attach and EntityState.Detached
body: <p>Why in this article:
  <a href="http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application" rel="nofollow">http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application</a>
  we have check if EntityState.Detached in Delete method and then Attach and in Update method we don't have check:</p>
  
  <pre><code>    public virtual void Delete(TEntity entityToDelete)
      {
          if (context.Entry(entityToDelete).State == EntityState.Detached)
          {
              dbSet.Attach(entityToDelete);
          }
          dbSet.Remove(entityToDelete);
      }
  
      public virtual void Update(TEntity entityToUpdate)
      {
          dbSet.Attach(entityToUpdate);
          context.Entry(entityToUpdate).State = EntityState.Modified;
      }
  </code></pre>