If Repository Pattern is overkill for modern ORMs (EF, nHibernate), what is a better abstraction

domain-driven-designentity-frameworknhibernateormrepository-pattern

I've recently read a lot of arguments against using the repository pattern with powerful ORM's like Entity Framework as it incorporates repository-like functionality, along with Unit of Work functionality as well.

Another argument against using the pattern for a situation like unit testing is that the repository pattern is a leaky abstraction since the more generic implementations leverage IQueryable.

The arguments against using the repository pattern make sense to me, but the alternative methods of abstractions suggested are often more confusing and appear just as overkill as the problem.

Jimmy Bogards solution seems to be a mix of blowing the abstractions away, but also introducing his own architecture.
https://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-over-repositories/

Another example of repositories being unnecessarily….but use my architecture!
http://blog.gauffin.org/2012/10/22/griffin-decoupled-the-queries/

Another…
http://www.thereformedprogrammer.net/is-the-repository-pattern-useful-with-entity-framework

I haven't found a clear replacement or alternative to the "overly complex" repository pattern approach that isn't more architected itself.

Best Answer

I think you are conflating repositories and generic repositories.

A basic repository just interfaces your data store and provides methods to return the data

IRepository {
   List<Data> GetDataById(string id);
}

It doesn't leak the data layer into your code via an IQueryable or other ways of passing in random queries and provides a well defined testable and injectable surface of methods.

A Generic Repository allows you to pass in your query much like an ORM

IGenericRepository<T> {
    List<T> Get<T>(IQuery query);
    //or
    IQueryable<T> Get<T>();
}

I agree there isn't much point using a Generic Repository on top of an ORM which is basically just another Generic Repository.

The answer is to use the basic Repository pattern to hide your ORM