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.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Alex
  • 1,357
  • 3
  • 18
  • 41

1 Answers1

3

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.

Community
  • 1
  • 1
Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • 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 Jun 01 '10 at 04:13
  • I added some information about batch fetching, but I already had outlined the normal paging, including collection paging. – Mauricio Scheffer Jun 01 '10 at 04:35
  • I mean e.g. [HasMany(typeof(Conversation), Table = "Conversation", ColumnKey = "ContactId", Cascade = ManyRelationCascadeEnum.All, Lazy = true, Inverse = true)] internal IList History If I use such attribute as HasMany, my collection will be loaded as whole. – Alex Jun 01 '10 at 09:22