title: NHibernate N+1 select : architectural solution?
body: <p>Considering the following "database" :</p>
  
  <pre><code>Post -&gt; User
  </code></pre>
  
  <p>The entities :</p>
  
  <pre><code>class User
  {
      public virtual string Name { get; set; }
      public virtual IList&lt;Post&gt; Posts { get; set; }
  }
  
  class Post
  {
      public virtual string Title { get; set; }
      public virtual User Author { get; set; }
  }
  </code></pre>
  
  <p>And the following service Layer:</p>
  
  <pre><code>class UserService
  {
      IRepositoryUsers repositoryUsers;
  
      IList&lt;User&gt; GetUsers()
      {
          return this.repositoryUsers.GetAllUsers();
      }
  }
  </code></pre>
  
  <p>When I want to print all users, with associated post count, I get (no surprise here) a N+1 select problem, as for each line, it will create a select to get the posts for the users.</p>
  
  <p>Now here is my question : what is the "best" way to handle this, as there are some cases when I don't want to eager load each user's posts.</p>
  
  <p>Should I create as many methods in my repository (and service) to match those scenarios ?</p>