title: How to abstract the Entities Data Context in C#
body: <p>In my application I created a DAL with a Repository class. The Repository uses a set of EF classes as <strong>Data Context</strong>.</p>
  
  <p>I would like to create an abstraction in order to be capable of using multiple <strong>Data Context</strong> with the <strong>same repository</strong>. I use the following code to initialize the context (<code>ProductEntities</code> is the EF context):</p>
  
  <pre><code>public class ProductRepository : IProductRepository
  {
       ?type? _productEntitiesContext;
  
       public productRepository()
       {
           _productEntitiesContext = new ProductEntities();
       }
  
       public productRepository(?type? productContext)
       {
           _productEntitiesContext = productContext;
       }
  }
  </code></pre>
  
  <p>But I do not know the type of <code>_productEntitiesContext</code> (and <code>productContext</code>). <code>ProductEntities</code> inherits from <code>ObjectContext</code>.</p>
  
  <p>In order to achieve abstraction I always use interfaces, I do not know whether I can use <code>ObjectContext</code> since it is a class. </p>
  
  <p>Anybody knows if my goal is achievable?</p>