title: Entity Framework Generic Repository
body: <p>I am writing a generic repository to be used for my every model CRUD operation using entity framework CTP5 as following:</p>
  
  <pre><code>  public class BaseRepository&lt;TEntity&gt; : IRepository&lt;TEntity&gt; where TEntity : BaseEntity
      {
          public DbContext Context { get; set; }
  
  
          public void Insert(TEntity entity)
          {
                  if (Context.Entry&lt;TEntity&gt;(entity).State == EntityState.Detached)
                  {
                      Context.Set&lt;TEntity&gt;().Attach(entity);
                  }
                  Context.Set&lt;TEntity&gt;().Add(entity);
                  Context.SaveChanges();
  
          }
          public void Delete(int id)
          {
                  TEntity entity = Context.Set&lt;TEntity&gt;().Find(id);
                  if (Context.Entry&lt;TEntity&gt;(entity).State == EntityState.Detached)
                  {
                      Context.Set&lt;TEntity&gt;().Attach(entity);
                  }
                  Context.Set&lt;TEntity&gt;().Remove(entity);
                  Context.SaveChanges();
  
          }
          public void Delete(TEntity entity)
          {
                  Context.Set&lt;TEntity&gt;().Remove(entity);
                  Context.SaveChanges();
  
          }
          public void Update(TEntity entity)
          {
                  TEntity status = Context.Set&lt;TEntity&gt;().Find(entity.Id);
                  status = entity;
                  Context.SaveChanges();
  
          }
  
  
  
          public TEntity GetFirst()
          {
  
                  var entity = Context.Set&lt;TEntity&gt;().FirstOrDefault();
                  if (entity == null) return null;
                  return entity;
  
  
          }
          public TEntity GetNext(int id)
          {
  
                  var entity = (from u in Context.Set&lt;TEntity&gt;()
                                where u.Id &gt; id
                                select u).FirstOrDefault();
                  if (entity == null) return null;
                  return entity;
  
          }
          public TEntity GetPrevoius(int id)
          {
  
                  var entity = (from u in Context.Set&lt;TEntity&gt;()
                                  where u.Id &lt; id
                                  orderby u.Id descending
                                  select u).FirstOrDefault();
                  if (entity == null) return GetFirst();
                  return entity;
          }
          public TEntity GetLast()
          {
  
                  var entity = (Context.Set&lt;TEntity&gt;().OrderByDescending(u =&gt; u.Id)).FirstOrDefault();
                  if (entity == null) return null;
                  return entity;
  
          }
          public TEntity GetById(int id)
          {
              return Context.Set&lt;TEntity&gt;().Find(id);
  
          }
          public int GetMaxId()
          {
  
                  var max = Context.Set&lt;TEntity&gt;().Count()+ 1;
                  return max;
  
          }
  }
  </code></pre>
  
  <p>everything works fine but Update method which nither doesnt generate any error nor save any changes back to database.
  Can anybody guid me how to solve this issue?</p>