Question

Assume this setup:

interface IRepo 
{ 
  IEnumerable<Project> GetAllProjects();
}

class RavenRepo : IRepo
{
  IEnumerable<Project> GetAllProjects()
  {
     return session.query<Project>();
  }
}

class ApplicationService
{
  IRepo repo;
  public IEnumerable<Project> GetProjectsOrderedBySomething()
  {
    return repo.GetAllProjects().OrderBy(...);
  } 
}

This works fine, but I would like to add paging, all the way back to the Repo. If I just add it to GetAllProjects, the OrderBy wont work. I see three options:

  1. Add a new method for every single new ordering.
  2. Return IQueryable.
  3. Pass a list of keySelectors.

I don't like the idea of deferring execution from outside the repository, but I guess option 2 is the most useful apart from that? Also, this puts the burden (and responsibility) of paging on the service, meaning that someone might miss the requirement to use paging.

Was it helpful?

Solution

As you found out, this is a pretty bad idea. See here for more details: http://www.wekeroad.com/2014/03/04/repositories-and-unitofwork-are-not-a-good-idea/

But, in general, don't use repositories with RavenDB.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top