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 f开发者_JAVA百科irst 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.
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 Post
s)
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.
精彩评论