NHibernate IQueryable Collection as Property of Root
Posted
by Khalid Abuhakmeh
on Stack Overflow
See other posts from Stack Overflow
or by Khalid Abuhakmeh
Published on 2010-05-05T14:28:42Z
Indexed on
2010/05/14
22:34 UTC
Read the original article
Hit count: 345
Hello and thank you for taking the time to read this.
I have a root object that has a property that is a collection.
For example :
I have a Shelf object that has Books.
// now
public class Shelf
{
public ICollection<Book> Books {get; set;}
}
// want
public class Shelf
{
public IQueryable<Book> Books {get;set;}
}
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.
var shelf = shelfRepository.Get(1);
var filtered = from book in shelf.Books
where book.Name == "The Great Gatsby"
select book;
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).
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.
I would like to do this implicitly so that when NHibernate sees and IQueryable on my class it knows what to do.
I have looked at NHibernates 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.
Linq To SQL offers something similar to what I'm talking about.
© Stack Overflow or respective owner