title: Does anyone have a very complete example generic repository for EF 6.1?
body: <p>I have my own repository that is as follows. However this does not take into account some of the new features such as the range features. Does anyone have a repository that includes everything.  I have searched for this on the net but there's nothing that I can find that is recent. Here is what I have. I am hoping for something that has more and that offers IQueryable for many of the methods:</p>
  
  <pre><code>namespace Services.Repositories
  {
      /// &lt;summary&gt;
      /// The EF-dependent, generic repository for data access
      /// &lt;/summary&gt;
      /// &lt;typeparam name="T"&gt;Type of entity for this Repository.&lt;/typeparam&gt;
      public class GenericRepository&lt;T&gt; : IRepository&lt;T&gt; where T : class
      {
          public GenericRepository(DbContext dbContext)
          {
              if (dbContext == null) 
                  throw new ArgumentNullException("An instance of DbContext is required to use this repository", "context");
              DbContext = dbContext;
              DbSet = DbContext.Set&lt;T&gt;();
          }
  
          protected DbContext DbContext { get; set; }
  
          protected DbSet&lt;T&gt; DbSet { get; set; }
  
          public virtual IQueryable&lt;T&gt; Find(Expression&lt;Func&lt;T, bool&gt;&gt; predicate)
          {
              return DbSet.Where&lt;T&gt;(predicate);
          }
  
          public virtual IQueryable&lt;T&gt; GetAll()
          {
              return DbSet;
          }
  
          public virtual T GetById(int id)
          {
              //return DbSet.FirstOrDefault(PredicateBuilder.GetByIdPredicate&lt;T&gt;(id));
              return DbSet.Find(id);
          }
  
          public virtual void Add(T entity)
          {
              DbEntityEntry dbEntityEntry = DbContext.Entry(entity);
              if (dbEntityEntry.State != EntityState.Detached)
              {
                  dbEntityEntry.State = EntityState.Added;
              }
              else
              {
                  DbSet.Add(entity);
              }
          }
  
          public virtual void Update(T entity)
          {
              DbEntityEntry dbEntityEntry = DbContext.Entry(entity);
              if (dbEntityEntry.State == EntityState.Detached)
              {
                  DbSet.Attach(entity);
              }  
              dbEntityEntry.State = EntityState.Modified;
          }
  
          public virtual void Delete(T entity)
          {
              DbEntityEntry dbEntityEntry = DbContext.Entry(entity);
              if (dbEntityEntry.State != EntityState.Deleted)
              {
                  dbEntityEntry.State = EntityState.Deleted;
              }
              else
              {
                  DbSet.Attach(entity);
                  DbSet.Remove(entity);
              }
          }
  
          public virtual void Delete(int id)
          {
              var entity = GetById(id);
              if (entity == null) return; // not found; assume already deleted.
              Delete(entity);
          }
      }
  }
  </code></pre>