title: What are the advantages to the Generic Repository Pattern + UOW Pattern with an ORM like Entity Framework
body: <p>Let's start with two quotes that sums this issue up:
  "Wrapping up DbContext is a leaky abstraction. No matter what, you'll end up in some kind of dependency on EF in your services/controller layer." <a href="https://codereview.stackexchange.com/questions/11785/ef-code-first-with-repository-unitofwork-and-dbcontextfactory">quote ref</a>
   And the second quote:</p>
  
  <p>"DbContext Class</p>
  
  <p>Represents a combination of the Unit-Of-Work and Repository patterns and enables you to query a database and group together changes that will then be written back to the store as a unit." <a href="http://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext%28v=vs.103%29.aspx" rel="nofollow noreferrer">MSDN</a></p>
  
  <p>Please do not say that the repository pattern allows you to simply swap out your database, it does not. Has anyone even ever done that with a mature application? Please also do not answer that the Repository pattern should not expose IQueryable, I think that is just another way saying you don't trust the people you work with.</p>
  
  <p>I am all for encapsulation, code coverage/testability but since this popular repo pattern for EF exposes IQueryable there is no longer a need for the pattern it seems:</p>
  
  <pre><code>   public interface IRepository&lt;T&gt; where T : class
      {
      IQueryable&lt;T&gt; GetAll();
      T GetById(int id);
      IEnumerable&lt;T&gt; Get(Expression&lt;Func&lt;T, bool&gt;&gt; filter = null,Func&lt;IQueryable&lt;T&gt;,IOrderedQueryable&lt;T&gt;&gt; orderBy = null, string includeProperties = "");
      void Add(T entity);
      void Update(T entity);
      void Delete(T entity);
      void Delete(int id);
  }
  </code></pre>
  
  <p>The only benefits of the repository pattern combined with the UOW pattern are:
  1.  Easily enable the Dependency Injection pattern for increase testability/code coverage
  2.  Encapsulate the complexity that exists with external integration (web service calls to different vendors, web apis, databases, etc..)</p>
  
  <p>So what encapsulation am I getting that I do not get by using MyDbContext : DbContext class? My ORM is the abstraction Sure I get some uniformity of the controllers with the UOW of work and the common queries like Add and Delete, but is that really worth the effort. Can't I just trust my developers to be uniform and when they do it a little their way, just don't get OCD about it.  AND since a controller can write any query it wants does this not fly in the face of unit testing? AND (even larger caps lol) if I have a third party API to call, I can make this accessible in MyDbContext class for the controllers so it seems like just another data call to the controller.</p>
  
  <p>I say again, why not use the ORM directly, it is the data abstraction!</p>
  
  <p>Here is some arguments against the repository pattern:</p>
  
  <p><a href="http://ayende.com/blog/4784/architecting-in-the-pit-of-doom-the-evils-of-the-repository-abstraction-layer" rel="nofollow noreferrer">http://ayende.com/blog/4784/architecting-in-the-pit-of-doom-the-evils-of-the-repository-abstraction-layer</a></p>
  
  <p><a href="http://ayende.com/blog/3955/repository-is-the-new-singleton" rel="nofollow noreferrer">http://ayende.com/blog/3955/repository-is-the-new-singleton</a></p>
  
  <p><a href="http://lostechies.com/jimmybogard/2012/09/20/limiting-your-abstractions/" rel="nofollow noreferrer">http://lostechies.com/jimmybogard/2012/09/20/limiting-your-abstractions/</a></p>
  
  <p><a href="http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/" rel="nofollow noreferrer">http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/</a></p>
  
  <p>Here is a proper argument for the repository pattern (not convincing enough though):
  <a href="http://www.sapiensworks.com/blog/post/2012/10/10/Do-We-Need-The-Repository-Pattern.aspx" rel="nofollow noreferrer">http://www.sapiensworks.com/blog/post/2012/10/10/Do-We-Need-The-Repository-Pattern.aspx</a></p>