views:

89

answers:

1

Does CastleProject ActiveRecord support paging? I need to load only data which is now seen on the screen. If I use [HasMany], it will be loaded as a whole either immediately or at the first call (if lazy attribute is true). However I only need something like first 100 records (then maybe 100 next records).

Another question is how to load only 100 items. If the collection is too big, memory can reach its limit if we constantly load more and more items.

+3  A: 

Yes, Castle ActiveRecord supports paging. In addition to NHibernate's API for paging, you can use SlicedFindAll(), e.g.:

Post[] posts = Post.SlicedFindAll(10, 20);

where 10 is the first result index and 20 the page size (it will return an array of 20 Posts)

You can also define criteria, for example to fetch the first 100 comments of a post:

Post post = ...    
Comment[] comments = Comment.SlicedFindAll(0, 100, Restrictions.Eq("Post", post));

You can also "page" collections by using batch fetching (which corresponds to the BatchSize property in HasManyAttribute), but this batch size is fixed so it's not as flexible as the normal paging approach.

Mauricio Scheffer
Thanks Mauricio. Can you please clarify if this can be integrated to markup. I mean, if I use HasMany attribute, how can I prevent from loading all collection contents from database?
Alex
I don't understand what you mean by 'markup'. HTML?
Mauricio Scheffer
I added some information about batch fetching, but I already had outlined the normal paging, including collection paging.
Mauricio Scheffer
I mean e.g.[HasMany(typeof(Conversation), Table = "Conversation", ColumnKey = "ContactId", Cascade = ManyRelationCascadeEnum.All, Lazy = true, Inverse = true)]internal IList<Conversation> HistoryIf I use such attribute as HasMany, my collection will be loaded as whole.
Alex