title: Updating records using a Repository Pattern with Entity Framework 6
body: <p>I'm writing a simple blog application and trying to establish CRUD operations in my generic repository pattern but I'm getting an error on my update method that says:</p>
  
  <blockquote>
    <p>'System.Data.Entity.DbSet' does not contain a definition for
    'Entry' and no extension method 'Entry' accepting a first argument of
    type 'System.Data.Entity.DbSet' could be found (are you missing a
    using directive or an assembly reference?)</p>
  </blockquote>
  
  <p>I followed a <a href="https://stackoverflow.com/questions/5035323/mocking-or-faking-dbentityentry-or-creating-a-new-dbentityentry">post that explained</a> how to 'fake' Entry() by adding additional level of indirection over DbContext. However in MVC 5 we're inheriting from: <strong>IdentityDbContext</strong> and not DbContext. I did try implementing the authors fix but the error persists.</p>
  
  <h2>My Question</h2>
  
  <p>How can I add an update method to my repository in Entity Framework 6 using IdentityDbContext? If we aren't supposed to do it this way then how do I update a record with this pattern?</p>
  
  <p>I should note that all other the other methods work as expected.</p>
  
  <p><strong>My generic Repository:</strong></p>
  
  <pre><code>public class BlogEngineRepository&lt;T&gt; : IRepository&lt;T&gt; where T : class
      {
          protected DbSet&lt;T&gt; DbSet;
  
          public BlogEngineRepository(DbContext dataContext)
          {
              DbSet = dataContext.Set&lt;T&gt;();
          }
  
          #region IRepository&lt;T&gt; Members
  
          public void Insert(T entity)
          {
              DbSet.Add(entity);
          }
  
          public void Delete(T entity)
          {
              DbSet.Remove(entity);
          }
  
          public void Update(T entity)
          { 
  
             DbSet.Entry(entity).State = System.Data.Entity.EntityState.Modified;
  
          }
  
          public IQueryable&lt;T&gt; SearchFor(Expression&lt;Func&lt;T, bool&gt;&gt; predicate)
          {
              return DbSet.Where(predicate);
          }
  
          public IQueryable&lt;T&gt; GetAll()
          {
              return DbSet;
          }
  
          public T GetById(int id)
          {
              return DbSet.Find(id);
          }
  
          #endregion
      }
  </code></pre>