title: Do we need to use the Repository pattern when working in ASP.NET MVC with ORM solutions?
body: <p>I am bit curious as to what experience other developers have of applying the Repository pattern when programming in ASP.NET MVC with Entity Framework or NHibernate. It seems to me that this pattern is already implemented in the ORM themselves. <strong><code>DbContext</code></strong> and <strong><code>DbSet&lt;T&gt;</code></strong> in the Entity Framework and by the <strong><code>ISession</code></strong> in NHibernate. Most of the concerns mentioned in the <strong><code>Repository</code></strong> pattern - as catalogued in <a href="http://martinfowler.com/eaaCatalog/repository.html" rel="noreferrer">POEE</a> and <a href="http://domaindrivendesign.org/node/123" rel="noreferrer">DDD</a> - are pretty adequately implemented by these ORMs. Namely these concerns are,</p>
  
  <ul>
  <li>Persistence </li>
  <li>OO View of the data</li>
  <li>Data Access Logic Abstraction</li>
  <li>Query Access Logic</li>
  </ul>
  
  <p>In addition, most of the implemententations of the repository pattern that I have seen follow this implementation pattern - assuming that we are developing a blog application.</p>
  
  <p>NHibernate implementation:</p>
  
  <pre><code>public class PostRepository : IPostRepository
  {
      private ISession _session;
  
      public PostRepository(ISession session)
      {
          _session = session;
      }
  
      public void Add(Post post)
      {
          _session.Save(post);
      }
  
      // other crud methods. 
  }
  </code></pre>
  
  <p>Entity Framework:</p>
  
  <pre><code>public class PostRepository : IPostRepository
  {
      private DbContext _session;
  
      public PostRepository(DbContext session)
      {
          _session = session;
      }
  
      public void Add(Post post)
      {
          _session.Posts.Add(post);
          -session.SaveChanges();
      }
  
      // other crud methods. 
  }
  </code></pre>
  
  <p>It seems to me that when we are using ORMs - such as Nhibernate or Entity Framework - creating these repository implementation are redundant. Furthermore since these pattern implementations does no more than what is already there in the ORMS, these act more as <strong>noise</strong> than helpful OO abstractions. It seems using the repository pattern in the situation mentioned above is nothing more than <em>developer self aggrandizement</em> and more pomp and ceremony without any realizable techical benefits. What are your thoughts ??</p>