title: Generic access to DbContext
body: <p><code>ObjectContext</code> allows generic access to the generated Entities. <code>DbContext</code> appears to have no such support.  Accessing EF5 with a generic repository is challenging.  Let's say I want a generic mechanism to read any given entity, call it TEntity:</p>
  
  <pre><code>public class DataRepositoryEF5&lt;T&gt; where T: DbContext
  {
      private ObjectContext _context;        
  
      public DataRepositoryEF5(DbContext context)
      {
          _context = ((IObjectContextAdapter)context).ObjectContext;
      }
  
      public IEnumerable&lt;TEntity&gt; ReadAll&lt;TEntity&gt;() where TEntity : class,new()
      {
          return GetObjectSet&lt;TEntity&gt;().AsEnumerable();
      }
  
      protected ObjectSet&lt;TEntity&gt; GetObjectSet&lt;TEntity&gt;() where TEntity : class,new()
      {
          ObjectSet&lt;TEntity&gt; result;
          result = _context.CreateObjectSet&lt;TEntity&gt;();
          return result;
      }
  }
  </code></pre>
  
  <p>Usage</p>
  
  <pre><code>            var context = new MyContext();            
              var repository = new DataRepositoryEF5&lt;MyContext&gt;(context);
  
              IEnumerable&lt;Document&gt; results = repository.GetAll&lt;Document&gt;();
  
              foreach (var item in results)
              {
                  Console.WriteLine("{0} {1} {2} {3}", item.Description, item.Id, item.Property, item.Whatever);
              }
  </code></pre>
  
  <p>EF used to generate classes with a common base type <code>EntityObject</code>. Since that is no longer the case the best constraint I can have is <code>class</code>...</p>
  
  <p>Second, because there is no equivalent of <code>ObjectContext.CreateObjectSet&lt;&gt;()</code> I am forced to cast from <code>DbSet</code> to <code>ObjectSet</code>.  </p>
  
  <p>With this pattern in place I have no need for <code>DbContext</code>.  Without generics I am forced to hand code all CRUD operations.  Did I miss something? If not, is it possible to tell EF5 to generate code with <code>ObjectContext</code> instead?</p>