title: Repository pattern should I use ObjectSet<T> vs IDbSet<T> for base class?
body: <p>I'm trying to create a base repository class based off the <code>MyFinance</code> example that uses Entity Framework Code first.  I'd like to change it to use just Entity Framework.  The sample uses <code>IDbSet</code>, but I have no idea what to change it to for just vanilla Entity Framework.  Maybe <code>ObjectSet&lt;T&gt;</code>?  When I use <code>ObjectSet&lt;T&gt;</code> I lose some of the methods such as <code>GetById</code> so maybe that isn't 100% right.  Any help would be greatly appreciated.</p>
  
  <p><strong>Sample repository base using Entity Framework code first</strong></p>
  
  <pre><code>public abstract class RepositoryBase&lt;T&gt; where T : class
  {
  private MyFinanceContext dataContext;
  private readonly IDbSet&lt;T&gt; dbset;
  protected RepositoryBase(IDatabaseFactory databaseFactory)
  {
      DatabaseFactory = databaseFactory;
      dbset = DataContext.Set&lt;T&gt;();
  }
  
  protected IDatabaseFactory DatabaseFactory
  {
      get; private set;
  }
  
  protected MyFinanceContext DataContext
  {
      get { return dataContext ?? (dataContext = DatabaseFactory.Get()); }
  }
  public virtual void Add(T entity)
  {
      dbset.Add(entity);           
  }
  public virtual void Update(T entity)
  {
      dbset.Attach(entity);
      dataContext.Entry(entity).State = EntityState.Modified;
  }
  public virtual void Delete(T entity)
  {
      dbset.Remove(entity);           
  }
  public virtual void Delete(Expression&lt;Func&lt;T, bool&gt;&gt; where)
  {
      IEnumerable&lt;T&gt; objects = dbset.Where&lt;T&gt;(where).AsEnumerable();
      foreach (T obj in objects)
          dbset.Remove(obj);
  } 
  public virtual T GetById(long id)
  {
      return dbset.Find(id);
  }
  public virtual T GetById(string id)
  {
      return dbset.Find(id);
  }
  public virtual IEnumerable&lt;T&gt; GetAll()
  {
      return dbset.ToList();
  }
  public virtual IEnumerable&lt;T&gt; GetMany(Expression&lt;Func&lt;T, bool&gt;&gt; where)
  {
      return dbset.Where(where).ToList();
  }
  public T Get(Expression&lt;Func&lt;T, bool&gt;&gt; where)
  {
      return dbset.Where(where).FirstOrDefault&lt;T&gt;();
  } 
  </code></pre>
  
  <p>}</p>
  
  <p><strong>What I think I should change it to for EntityFramework</strong></p>
  
  <pre><code>public abstract class BaseRepository&lt;T&gt; where T : class
  {
      private MyDBContainer _dataContext;
      private readonly ObjectSet&lt;T&gt; dbset;
  
      protected BaseRepository(IDatabaseFactory databaseFactory)
      {
          DatabaseFactory = databaseFactory;
          dbset = DataContext.CreateObjectSet&lt;T&gt;();
      }
  
      protected IDatabaseFactory DatabaseFactory
      {
          get;
          private set;
      }
  
      protected MyDBContainer DataContext
      {
          get { return _dataContext ?? (_dataContext = DatabaseFactory.DataContext); }
      }
      public virtual void Add(T entity)
      {
          dbset.AddObject(entity);
      }
      //public virtual void Update(T entity)
      //{
      //    dbset.Attach(entity);
      //    _dataContext.Entry(entity).State = EntityState.Modified;
      //}
      public virtual void Delete(T entity)
      {
          dbset.DeleteObject(entity);
      }
      public virtual void Delete(Expression&lt;Func&lt;T, bool&gt;&gt; where)
      {
          IEnumerable&lt;T&gt; objects = dbset.Where&lt;T&gt;(where).AsEnumerable();
          foreach (T obj in objects)
              dbset.DeleteObject(obj);
      }
      //public virtual T GetById(long id)
      //{
      //    return dbset.(id);
      //}
      //public virtual T GetById(string id)
      //{
      //    return dbset.Find(id);
      //}
      public virtual IEnumerable&lt;T&gt; GetAll()
      {
          return dbset.ToList();
      }
      public virtual IEnumerable&lt;T&gt; GetMany(Expression&lt;Func&lt;T, bool&gt;&gt; where)
      {
          return dbset.Where(where).ToList();
      }
      public T Get(Expression&lt;Func&lt;T, bool&gt;&gt; where)
      {
          return dbset.Where(where).FirstOrDefault&lt;T&gt;();
      }
  
  }
  </code></pre>