title: Generic entity save method not working?
body: <p>In an attempt to reduce the amount of code and classes I use I have been given this method:</p>
  
  <pre><code>public TEntity Save(TEntity entity)
              {
                  var validatationErrors = Entities.GetValidationErrors().ToList();
                  if (validatationErrors.Count() &gt; 0)
                      throw new ValidateException(validatationErrors);
  
                  if (Entities.Entry(entity).State == EntityState.Added)
                      Entities.Set&lt;TEntity&gt;().Add(entity);
                  else
                      Entities.Set&lt;TEntity&gt;().Attach(entity);
  
                  Entities.SaveChanges();
                  Entities.Entry(entity).Reload();
                  return entity;
              }
  </code></pre>
  
  <p>When I create a new Product however it skips the conditional that would Add it to the database. Therefore not getting saved. Same is if I try to modify something it doesn't change.</p>
  
  <p>To remedy this I have to save my entities in the controller like so:</p>
  
  <pre><code>using (var db = new EntitiesDbContext())
                  {
                      db.Products.Attach(product);
                      db.Entry(product).State = EntityState.Modified;
                      db.SaveChanges();
                  }
  </code></pre>
  
  <p>This seems rather inefficient.
  So I was wondering really what's wrong with the generic save that makes it not work?</p>