title: EntityFramework in an Onion archetctured project
body: <p>I have a ASP.NET WebAPI 2 project that uses Ninject as IoC. I have a core layer that all my Class Library projects use, and that defines common interfaces.</p>
  
  <p>I have a layer called Repositories where I put my applications repositories, and a layer called DataLayer that defines the different Entity Framework DbContext objects. My Repositories layer has a reference to my DataLayer, and on both the DataLayer and the Repositories Layer I've added EntityFramework.</p>
  
  <p>All repositories classed inside repositories layers are implementing common interfaces from the core, and are injected to the contollers in the API using ninject. At first, when I ran my project and tried to do something against the repository, I got the following error message:</p>
  
  <pre><code>An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code
  
  Additional information: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
  </code></pre>
  
  <p>What I did next is open the app.config file in the repository layer and copy the EntityFramework defenitions to my web.config in the API project:</p>
  
  <pre><code>&lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
  &lt;/configSections&gt;
  
  &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"&gt;
        &lt;parameters&gt;
          &lt;parameter value="mssqllocaldb" /&gt;
        &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
  &lt;/entityFramework&gt;
  </code></pre>
  
  <p>but now I get the following error:</p>
  
  <pre><code>An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code
  
  Additional information: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
  </code></pre>
  
  <p>I don't think that the solution is including the entity framework in the API references because that would break the separation of concerns - the API shouldn't care what technology is used by the repository to access the data - so that if lets say in a month I would like to change my ORM or even my db, the API should not care what and how I use, as long as it uses the same interfaces.</p>
  
  <p>What is the problem then? I'm new to EF, so I figure I must be missing something...</p>