Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3452816
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:18:09+00:00 2026-05-18T09:18:09+00:00

I want to return one Parent object with the children collection eagerly loaded with

  • 0

I want to return one Parent object with the children collection eagerly loaded with the requested page (subset) of children objects. What’s the best way to achieve this? Filters? Is is possible with an ICriteria query?

I’m using .SetFirstResult() and .SetMaxResults() to do paging for collections of aggregate root results, but is it possible to utilize this withing the aggregate root to select the page of children results?

Something along these lines:

public class Parent{
int Id;
IList<Child> Children;
}


public Parent GetWithPagedChildren(int id, int page, int pageSize, out int count)
{
    //Query

    return Parentresult; //With one page of children populated.
}

UPDATE:

Actually, the eagerly loading requirement is not so important. I just want the paged subset of the child objects loaded when I access them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:18:09+00:00Added an answer on May 18, 2026 at 9:18 am

    You can’t page and join-fetch child collections in the same query. But you can:

    • Use a query to get the (paged) parents and one to load all the collections for those parents (read http://ayende.com/Blog/archive/2010/01/16/eagerly-loading-entity-associations-efficiently-with-nhibernate.aspx for some concepts)
    • Set batch-size on the collections to your page size. This will accomplish more or less the same, but automatically. There’s even a patch that allows changing this dynamically: https://nhibernate.jira.com/browse/NH-2316

    Update (for the new requirements):

    As you’ve read, you can use session.CreateFilter to filter/sort/page a child collection. This works and it is supported everywhere.

    Additionally, there’s a patch (NH-2319; I will convert to an addin, as it’s unlikely to be accepted in the trunk) that allows using Linq for that. It’s limited to some collection types and requires the relationship to be bidirectional, but allows the following:

    var parent = GetParent();
    var secondPageOfChildrenByName = parent.Children.AsQueryable()
                                                    .OrderBy(c => c.Name)
                                                    .Skip(PageSize * 1)
                                                    .Take(PageSize)
                                                    .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to override access to one variable in a class, but return all
Is it possible to return querysets that return only one object per foreign key?
I have a parent class with several children. One of the children, has one
I have a flash object in my page that i want to make as
For a project I have some objects, one method is to load the parent
Is it possible to order a collection of parent objects by both a parent's
I want to return StudentId to use elsewhere outside of the scope of the
I want to return all application dates for the current month and for the
Using DQL I want to return all the documents under the Cabinet test .
In my SWT Java app I often want to return information from inside a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.