title: NHibernate IQueryable collection as property of root
body: <p>I have a root object that has a property that is a collection. </p>
  
  <p>For example:</p>
  
  <pre><code>I have a Shelf object that has Books.
  
  // Now
  public class Shelf 
  {
      public ICollection&lt;Book&gt; Books {get; set;}
  }
  
  // Want 
  public class Shelf 
  {
     public IQueryable&lt;Book&gt; Books {get;set;}
  }
  </code></pre>
  
  <p>What I want to accomplish is to return a collection that is IQueryable so that I can run paging and filtering off of the collection directly from the the parent.</p>
  
  <pre><code>var shelf = shelfRepository.Get(1);
  
  var filtered = from book in shelf.Books
                 where book.Name == "The Great Gatsby"
                 select book;
  </code></pre>
  
  <p>I want to have that query executed specifically by NHibernate and not a get all to load a whole collection and then parse it in memory (which is what currently happens when I use ICollection).</p>
  
  <p>The reasoning behind this is that my collection could be huge, tens of thousands of records, and a get all query could bash my database.</p>
  
  <p>I would like to do this implicitly so that when NHibernate sees an IQueryable on my class it knows what to do. </p>
  
  <p>I have looked at NHibernate's LINQ provider and currently I am making the decision to take large collections and split them into their own repository so that I can make explicit calls for filtering and paging.</p>
  
  <p><strong><em>LINQ To SQL offers something similar to what I'm talking about.</em></strong></p>