title: Generic Repository with different databases, entity types and dbcontext
body: <p>I have implemented a simple generic repository for my asp.net web api project following this easy to follow guide :</p>
  
  <p><a href="http://www.dataworks.ie/blog/entity_framework_5_with_automapper_and_repository_pattern" rel="nofollow">http://www.dataworks.ie/blog/entity_framework_5_with_automapper_and_repository_pattern</a></p>
  
  <p>That works fine. </p>
  
  <p>However my solution in development has two simple databases with the same schema - a SQL Server CE for test/dev and when running local (and offline) and a SQL Azure when online. Both have EF layers created in separate assemblies. I switch the <code>DbContext</code> via the <code>web.config</code> connection string in the constructor of  the context class. The problem is with my controller code. </p>
  
  <p>For e.g. if using Azure I would have</p>
  
  <pre><code>public ActionResult Index()
  {
      IGenericRepository&lt;MyProj.Data.SqlAzure.User&gt; userRepo = new GenericRepository&lt;MyProj.Data.SqlAzure.User&gt;();
  </code></pre>
  
  <p>if I'm using SQL Server CE, I would have</p>
  
  <pre><code>public ActionResult Index()
  {
      IGenericRepository&lt;MyProj.Data.SqlCe.User&gt; userRepo = new GenericRepository&lt;MyProj.Data.SqlCe.User&gt;();
  </code></pre>
  
  <p>So I have to manually change to the correct assembly namespace to reference my entities when I switch databases.</p>
  
  <p>Sorry if this has been done to death as haven't done one of these in awhile but what is the best/elegant solution for this scenario? The above one is very dirty looking. Also all my generic repository code is currently in a model folder in same namespace as the web app.</p>